Zend Routing Not Working

2.1k views Asked by At

I am trying to set up my zend route using the routes.ini and bootstrap but for some reason it is not able to route as expected. My routes.ini and bootstrap.php are as follows.

routes.ini

[production]
routes.guestbook.route = "/guestbook"
routes.guestbook.defaults.controller = guestbook
routes.guestbook.defaults.action = index

bootstrap.php

protected function _initRoutes() 
{

// Get Front Controller Instance

$front = Zend_Controller_Front::getInstance();

// Get Router
$router = $front->getRouter();

$router->addConfig(new Zend_Config_Ini(APPLICATION_PATH.'/configs/routes.ini', 'production'), 'routes');

}
2

There are 2 answers

6
Aurelio De Rosa On

After I've read your comment, I can assert that you can delete those statements (config and bootstrap) because what you want to achieve is the normal behavior of the zend framework default router unless you're using modules.

Thanks to FloydThreepwood who remeber me to write this detail.

0
Phil On

The easiest way to configure routing is by using the Zend_Application_Resource_Router.

Configuration goes in your application.ini file and that's it, no further code required.

As it appears you're using a static route (no variable path components), try this in your application.ini file

resources.router.routes.guestbook.type = "Zend_Controller_Router_Route_Static"
resources.router.routes.guestbook.route = "guestbook"
resources.router.routes.guestbook.defaults.module = "default"
resources.router.routes.guestbook.defaults.controller = "guestbook"
resources.router.routes.guestbook.defaults.action = "index"

Remove the _initRoutes() method from your Bootstrap class.


Also, this is just an aside but when using other resources such as the front controller in a bootstrap _init* method, you must ensure they've been properly bootstrapped. To do so, retrieve them like this

protected function _initSomething()
{
    // make sure resource is bootstrapped
    $this->bootstrap('frontController');

    // retrieve resource
    $front = $this->getResource('frontController');
}

See http://framework.zend.com/manual/en/zend.application.theory-of-operation.html#zend.application.theory-of-operation.bootstrap.dependency-tracking