开发者

Bootstrap function _initRouter() breaks my custom routes

I was following example 2 in Running a Zend Framework action from command line and I hit a fatal error

Fatal error: Zend_Controller_Router_Exception: Route logout is not defined

with a custom route and navigation which I define in application.ini as

resources.router.routes.logout.route = logout
resources.router.routes.logout.defaults.controller = authentication    
resources.router.routes.logout.defaults.action = logout
开发者_运维百科resources.navigation.pages.logout.label = "Logout"
resources.navigation.pages.logout.controller = "authentication"
resources.navigation.pages.logout.action = "logout"
resources.navigation.pages.logout.route = "logout"
resources.navigation.pages.logout.resource = "logout"

I've narrowed the cause of the error down to this bootstrap function:

protected function _initRouter ()
{
    if (PHP_SAPI == 'cli') {
        $this->bootstrap ('frontcontroller');
        $front = $this->getResource('frontcontroller');
        require_once APPLICATION_PATH. '/router/Cli.php';
        $front->setRouter (new Application_Router_Cli ());
        $front->setRequest (new Zend_Controller_Request_Simple ());
    }
}

What am I doing wrong here? The error is only present when not using CLI (and if I remove the _initRouter() it works as expected).


The syntax resources.router in your application.ini is for setting up the resource "router". The existence of a method called "_initRouter()" in your bootstrap also setups up a resource called "router". I think this clash is what's causing your problem, as only one of these will be run (I can't remember which takes precedence).

I'd suggest renaming your method to something like _initCliRouter().

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜