添加Zend_Controller_Router_Route替换默认路由

时间:2012-10-22 14:37:06

标签: php zend-framework zend-route

当我添加此路线时

$classes_router = new Zend_Controller_Router_Route(
    '/:filter1/:filter2/*',
    array(
        'module'     => 'course',
        'controller' => $filter_controller,
        'action'     => 'index',
        'filter1'    => '',
        'filter2'    => ''
    )
);

默认路由:module/:controller/:action不再起作用。请告诉我这是什么问题?

1 个答案:

答案 0 :(得分:2)

问题是对somemodule/somecontroller/someaction的请求将与您添加的路由匹配(将在默认路由之前进行检查)。您需要在路径中提供一些限制以确定它匹配的内容,可能通过限制:filter1变量的可能匹配项:

$classes_router = new Zend_Controller_Router_Route(
    '/:filter1/:filter2/*',
    array(
        'module'     => 'course',
        'controller' => $filter_controller,
        'action'     => 'index',
        'filter1'    => '',
        'filter2'    => ''
    ), array(
        'filter1' => '(value1|foo|somethingelse)'
    )
);

或添加静态前缀:

$classes_router = new Zend_Controller_Router_Route(
    '/filter/:filter1/:filter2/*',
    array(
        'module'     => 'course',
        'controller' => $filter_controller,
        'action'     => 'index',
        'filter1'    => '',
        'filter2'    => ''
    )
);