Zend框架为同一个控制器的多个路由

时间:2012-07-19 21:39:46

标签: zend-framework routes zend-route

我正在尝试在我的网站上设置Zend分页,以便我可以使用Paul Irish的jquery无限滚动插件,但我的路线遇到了问题。我目前为我的组织者页面设置了这些路线:

//Organizer searches
    $route = new Zend_Controller_Router_Route('organizer/index/:filter/:page',
                                                array('controller'=> 'organizer',
                                                'action'=> 'index')); 
    $router->addRoute('organizer', $route);
    $route = new Zend_Controller_Router_Route('organizer/index/:filter',
                                                array('controller'=> 'organizer',
                                                'action'=> 'index')); 
    $router->addRoute('organizer', $route);

它按此顺序正确匹配organizer/index/popular,但如果我在其上放置页码,则过滤器突然变为空。如果我切换订单,organizer/index/popular/2工作正常,但organizer/index/popular不再有效。我只能使用更具体的路由,因为那是我需要的分页,但我想包括两者以容纳尝试输入网址的用户,或者我忘记在我的代码中的某处更改链接。我可以使用Zend将多个路由合并到同一个控制器吗?如果是这样,我做错了什么?

2 个答案:

答案 0 :(得分:1)

您需要为路线指定不同的名称。你把它们称为'组织者',所以第二个每次都取代第一个。

您也可以通过设置页面变量的默认值来轻松地使用一条路线执行此操作:

$route = new Zend_Controller_Router_Route(
    'organizer/index/:filter/:page',
    array(
        'controller'=> 'organizer',
        'action'=> 'index',
        'page' => 1
    )
); 
$router->addRoute('organizer', $route);

答案 1 :(得分:0)

您添加到路由器的每个路由都必须具有唯一的名称,因此要添加的第二个路由必须具有不同的名称,因为使用当前代码覆盖路由organizer。将$router->addRoute()的第二次调用更改为以下内容:

$router->addRoute('organizer2', $route );
相关问题