“No default module defined” error in Zend Framework app
-
06-09-2019 - |
Question
I am in process of making my bootstrap.php file more organized, but after I put everything into separate static methods, I cannot load any page beyond index controller. E.g. if I try to open
http://localhost/zftutorial/login/index
I get
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message
'Invalid controller class ("Login_IndexController")' in C:\Program
Files\VertrigoServ\www\library\Zend\library\Zend\Controller\Dispatcher\Standard.php:341
Stack trace: #0 C:\Program
Files\VertrigoServ\www\library\Zend\library\Zend\Controller\Dispatcher\Standard.php(255):
Zend_Controller_Dispatcher_Standard->loadClass('IndexController') #1 C:\Program
Files\VertrigoServ\www\library\Zend\library\Zend\Controller\Front.php(934):
Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http),
Object(Zend_Controller_Response_Http)) #2 C:\Program
Files\VertrigoServ\www\zftutorial\public\index.php(18): Zend_Controller_Front->dispatch()
#3 C:\Program Files\VertrigoServ\www\zftutorial\public\index.php(138): Bootstrap::run() #4
{main} thrown in C:\Program
Files\VertrigoServ\www\library\Zend\library\Zend\Controller\Dispatcher\Standard.php on
line 341
and in my bootstrap file I seem to have defined where controllers chould be found:
public static function setupFrontController()
{
self::$frontController = Zend_Controller_Front::getInstance();
self::$frontController->throwExceptions(true);
self::$frontController->returnResponse(true);
self::$frontController->setBaseUrl('/zftutorial');
self::$frontController->setControllerDirectory(
array(
'default' => self::$root . '../application/controllers',
'admin' => self::$root . '../application/controllers',
'index' => self::$root . '../application/controllers',
'login' => self::$root . '../application/controllers',
'user' => self::$root . '../application/controllers'
)
);
self::$frontController->setParam('registry', self::$registry);
}
Perhaps it has to do something with routing, but my app worked fine with implicit routing before, e.g. other controllers worked well too. WHat is the source of above error? How can I test/find/fix it?
Solution
Looking at your stack trace the error is Invalid controller class ("Login_IndexController")
This suggests that the class Login_IndexController doesn't exist.
You should have a file called IndexController.php in the login module's controller directory. The structure you have at the moment won't work because two modules can't have a controller with the same name. Change the structure to
self::$frontController->setControllerDirectory(
array(
'default' => self::$root . '../application/modules/default/controllers',
'admin' => self::$root . '../application/modules/admin/controllers',
'index' => self::$root . '../application/modules/index/controllers',
'login' => self::$root . '../application/modules/login/controllers',
'user' => self::$root . '../application/modules/user/controllers'
)
);
Create the IndexController.php in self::$root . '../application/modules/login/controllers and make sure the class is called Login_IndexController