Route default is not defined
Note: This article was originally published at Planet PHP
on 28 November 2012.
Working this long with Zend Framework makes me do things that have become a real routine and I don't pay much attention to it.A So when I just add few custom routes to myA Zend FrameworkA application, I don't make a big fuss out of it. But apparently people do struggle with it. They get messages like this:Zend_Controller_Router_Exception: Route default is not defined
Apparently when you create custom routes,A Zend FrameworkA "forgets" about the default route, causing this error to appear.
To quickly resolve this issue, you just open up application/Bootstrap.php and add the following to your routines:
protected function _initDefaultRoutes()
{
$frontController = Zend_Controller_Front::getInstance();
$frontController-getRouter()-addDefaultRoutes();
}
If you already have routine for loading routes, just ensure you add the default routes!
protected function _initRouteSetup()
{
$frontController = Zend_Controller_Front::getInstance();
$router = $frontController-getRouter();
$config = new Zend_Config_Ini('/path/to/config.ini', APPLICATION_ENV);
$router-addConfig($config, 'routes');
// ensure you load the default routes as well!!!
$router-addDefaultRoutes();
}
With this blog article I hope to save a bunch of people a lot of time looking for an example and get on with building awesome applications.


