PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

Route default is not defined

Note: This article was originally published at Planet PHP on 29 November 2012.
Planet PHP
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.ASo when I just add few custom routes to myAZend FrameworkAapplication, 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,AZend 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.