Route default is not defined

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. So when I just add few custom routes to my Zend Framework 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, Zend Framework "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();

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!!!

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.


  1. I can't remember if we really introduced that, as it would break BC. But usually, the default route was always added unless you explicitly disable it.

  2. Well, I can set up a test routine to prove this issue is genuine, but over the years I just adapted myself this habit of adding it specifically to the Bootstrap routine.

    Might be worth while to investigate further though…

  3. I would like to see your test code for this too. I have had to add default routes when I explicitly removed them... but by default, they are the first in the stack (last precedence) and any new routes you add act as FIFO stacked routes.


Post a Comment

Popular Posts