开发者

Zend framework does not care about the Custom Route specified

I created a router and added to the controller like this

public function _initRouting() {          
    // Get Front Controller Instance         
    $front = Zend_Controller_Front::getInstance();  
    // Get Router
    $router = $front -> getRouter();
    $routePage = new Zend_Controller_Router_Route('/page/:action/:cat/:parent/:id', array(
        'controller' => 'page',
        'action'    => 'list',
        'cat'       => 'general',
        'parent'    =>开发者_Python百科 '0',
        'module'    => 'default'
    ));
    $router -> addRoute('page', $routePage);
}

First this router is not doing anything, whenever I navigation to /page/list/general/0/1, it takes the standard route, not the new route.


The only thing I can think of is the front controller resource has not been "bootstrapped" prior to your init method.

You should at least bootstrap and retrieve the front controller resource

protected function _initRouting()
{
    $this->bootstrap('frontController');
    $front = $this->getResource('frontController');
    // etc

Why don't you just skip creating a bootstrap init method and configure the router resource in your application config?

resources.router.routes.page.route = "page/:action/:cat/:parent/:id"
resources.router.routes.page.defaults.module = "default"
resources.router.routes.page.defaults.controller = "page"
resources.router.routes.page.defaults.action = "list"
resources.router.routes.page.defaults.cat = "general"
resources.router.routes.page.defaults.parent = "0"

As a test, I added the above config and created a PageController with this listAction

public function listAction()
{
    Zend_Debug::dump($this->getRequest()->getParams());
    exit;
}

Calling page/list/general/0/1 yields

array(6) {
  ["action"] => string(4) "list"
  ["cat"] => string(7) "general"
  ["parent"] => string(1) "0"
  ["id"] => string(1) "1"
  ["module"] => string(7) "default"
  ["controller"] => string(4) "page"
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜