Zend Framework:如何解决这些冲突的自定义路由?

时间:2010-11-02 17:24:46

标签: zend-framework

我正在尝试为以下默认路由创建自定义“RESTful”路由:

Default Route         =>       Desired Route
=============================================
/events/calendar                /events/calendar (stays the same, uses the default route /:controller/:action)
/events/view/id/47              /events/47 
/events/overview/id/47          /events/47/overview
/events/page/id/47/page-id/100  /events/47/page/100

我想保留默认路由,但改进以前的默认路由以提高可读性。我的路线应该如何实现这一目标?这是我到目前为止所做的,但它们相互冲突,所以我知道它们无法正常工作。

$router->addRoute('eventsCalendar', new Zend_Controller_Router_Route_Static('/events/calendar', array('controller' => 'events', 'action' => 'calendar')));
$router->addRoute('eventPage', new Zend_Controller_Router_Route('/events/:id/:action/*', array('controller' => 'events', 'action' => 'view')));

1 个答案:

答案 0 :(得分:2)

通过更改我添加路由的顺序(将静态路由移动到结尾),它修复了冲突。但是,我不确定这是否是最好的方法。

$router->addRoute('eventPage', new Zend_Controller_Router_Route('/events/:id/:action/*', array('controller' => 'events', 'action' => 'view')));
$router->addRoute('staticEventPage', new Zend_Controller_Router_Route('/events/:id/page/:page-id', array('controller' => 'events', 'action' => 'static-page')));
$router->addRoute('eventsCalendar', new Zend_Controller_Router_Route_Static('/events/calendar', array('controller' => 'events', 'action' => 'calendar')));