开发者

Where should I define custom routes in my ZF 1.10 app?

开发者 https://www.devze.com 2022-12-27 11:22 出处:网络
With the new Zend_Application/Zend_Application_Bootstrap classes I\'m confused as to where I should be applying my custom routes. For example, at the moment I have one route:

With the new Zend_Application/Zend_Application_Bootstrap classes I'm confused as to where I should be applying my custom routes. For example, at the moment I have one route:

protected function _initRouter() {
    $router = new Zend_Controller_Router_Rewrite;
    $route = new Zend_Controller_Router_Route('news/:id', 
        array('controller' => 'news', 'action' => 'view'));
    $router->addRoute('postArchive', $route);           
}

This method is in my Zend_Application_Bootstrap_Bootstrap and is definitely run. The route is also applied in $router.

As I see it I could be do开发者_如何学Pythoning two things wrong - either the wrong place to add these routes, or not adding to the correct router. Can anyone point me in the right direction with this?


Looks like you are not passing the router to the front controller:

protected function _initRouter() 
{
    $this->bootstrap('frontController');
    $front = Zend_Controller_Front::getInstance(); // from singleton, for example
    $router = $front->getRouter();
    $route = new Zend_Controller_Router_Route('news/:id', 
        array('controller' => 'news', 'action' => 'view'));
    $router->addRoute('postArchive', $route);  

    return $router;
}


resources.router.routes.www.type = "Zend_Controller_Router_Route_Hostname" resources.router.routes.www.route = ":module.domain.tld" resources.router.routes.www.defaults.module = "default" resources.router.routes.www.chains.index.type = "Zend_Controller_Router_Route" resources.router.routes.www.chains.index.route = ":controller/:action/*" resources.router.routes.www.chains.index.defaults.controller = "index" resources.router.routes.www.chains.index.defaults.action = "index"

This view lines in the application.ini file in the bootstrap section did the job for me...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号