0

在我的管理模块中,在索引控制器中,我有多个过滤选项。根据参数,过滤非常简单,即:

http://www.site.com/admin/pages/by/date_added/order/asc  
-> This orders the pages by "date_added" ascending

http://www.site.com/admin/pages/status/published
-> This shows only the pages with status "published"

http://www.site.com/admin/pages/category/cars
-> This show only the pages under the "cars" category.

然后在我的应用程序引导程序中,我构建了这样的路线:

$route = new Zend_Controller_Router_Route_Regex("^admin/pages/status/([a-z,_]+)$", 
    array(
       "module" => "admin",
       "controller" => "pages",
       "action" => "index"
    ),
    array(
       1 => 'by',
       2 => 'order',
    )
);
$router->addRoute("admin/pages/order", $route); 

问题是我不知道如何组合所有这些参数,但也让它们成为可选的。例如我不想有这样的链接:

http://www.site.com/admin/pages/by/date_added/order/asc/category/cars

或者...

http://www.site.com/admin/pages/category/cars/status/published
4

1 回答 1

1

尝试这个:

$route = new Zend_Controller_Router_Route("admin/pages/*", 
    array(
       "module" => "admin",
       "controller" => "pages",
       "action" => "index"
    )
);
$router->addRoute("admin/pages/order", $route); 

*让它key/value成对匹配变量。因此,您的示例 URLhttp://www.example.com/admin/pages/by/date_added/order/asc/category/cars应该匹配,并且将具有路由 paramsby以及order来自categoryURL 的值。(可通过您的控制器访问。$this->_getParam('order')等等。

于 2013-10-08T13:21:05.460 回答