Trouble getting a modular Zend Framework project started

3.9k views Asked by At

I'm trying to set up a modular Zend Framework project with frontend and backend modules, but I just can't get it working. When I visit my public directory in a web browser, I get this error message:

Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in /usr/share/ZendFrameworkCli/library/Zend/Controller/Dispatcher/Standard.php:248 Stack trace: #0 /usr/share/ZendFrameworkCli/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 /usr/share/ZendFrameworkCli/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch() #2 /usr/share/ZendFrameworkCli/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() #3 /Users/Martin/Dropbox/Repositories/realestatecms/public/index.php(25): Zend_Application->run() #4 {main} Next exception 'Zend_Controller_Exception' with message 'Invalid controller specified (error)#0 /usr/share/ZendFrameworkCli/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) in /usr/share/ZendFrameworkCli/library/Zend/Controller/Plugin/Broker.php on line 336

I have created the two modules using the Zend Framework command line tool, and those two module directories have Bootstrap.php with two classes in called Frontend_Bootstrap and Backend_Bootstrap respectively.

My application.ini file looks as follows:

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/frontend/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.params.displayExceptions = 0
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
...

What have I done wrong? How do I get my Frontend_IndexController() to run when I visit http://example.com/public in my browser?

EDIT: If I update my configuration file with the lines as per Ivan's answer, I now get this error message:

Fatal error: Uncaught exception 'Zend_Application_Resource_Exception' with message 'Bootstrap file found for module "default" but bootstrap class "Default_Bootstrap" not found' in /usr/share/ZendFrameworkCli/library/Zend/Application/Resource/Modules.php:83 Stack trace: #0 /usr/share/ZendFrameworkCli/library/Zend/Application/Bootstrap/BootstrapAbstract.php(683): Zend_Application_Resource_Modules->init() #1 /usr/share/ZendFrameworkCli/library/Zend/Application/Bootstrap/BootstrapAbstract.php(626): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('modules')

2 /usr/share/ZendFrameworkCli/library/Zend/Application/Bootstrap/BootstrapAbstract.php(586):

Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap(NULL) #3 /usr/share/ZendFrameworkCli/library/Zend/Application.php(355): Zend_Application_Bootstrap_BootstrapAbstract->bootstrap(NULL) #4 /Users/Martin/Dropbox/Repositories/realestatecms/public/index.php(25): Zend_Application->bootstrap() #5 {main} thrown in /usr/share/ZendFrameworkCli/library/Zend/Application/Resource/Modules.php on line 83

Where is it getting Default_Bootstrap from as a class name?!

3

There are 3 answers

0
Jules On BEST ANSWER

I had the same problem and I found the solution on this page: http://updel.com/zend-framework-modular-application/

You have to comment the following line in /MyApp/application/configs/application.ini:

resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

like this:

;resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

It fixed the problem, unfortunately I am not skilled enough to explain/understand why, sorry. :-)

I hope it helps though.

3
kingdaemon On

did you change this line:

resources.frontController.controllerDirectory = APPLICATION_PATH "/frontend/controllers"

I think it should be like this:

resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

Then if you need other default module/controller than index/index use these configuration options:

resources.frontController.defaultControllerName = "index"
resources.frontController.defaultAction = "index"
resources.frontController.defaultModule = "frontend"

And you shouldnt access http://yoursite.com/public. It will raise error. Public directory should be your web DocumentRoot and you would access it like this: http://yoursite.com/

0
RockyFord On

Martin, when you call http://example.com/public Zend Framework will throw the error you saw because the router is looking for a controller named public.
The normal way to view the a Zend Frame work web site is to call http://example.com or http://example.com/index.php.
All requests to the application are routed through /application/public/index.php.

It looks like your original configuration for:

resources.frontController.controllerDirectory = APPLICATION_PATH "/frontend/controllers"

was likely correct for your application.

These are the typical lines in the application.ini for enabling modules

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.moduleControllerDirectoryName = "controllers"
resources.frontController.params.prefixDefaultModule = ""//Frontend may be your default
resources.modules = ""

you may have some differences depending on structure.
Also it is usually helpful for each module directory to include it's own bootstrap.php that extends *Zend_Application_Module_Bootstrap*

class Admin_Bootstrap extends Zend_Application_Module_Bootstrap {
    //put your code here
}

If this doesn't help fix your problem please include your directory structure and your application.ini(you can leave out db settings and such), Index.php would be helpful if it has been changed from default.
Also please include your version of Zend Framework.