开发者

Zend Framework: How to resolve these conflicting custom routes?

开发者 https://www.devze.com 2023-01-22 22:50 出处:网络
I am trying to create custom \"RESTful\" routes for the following default routes: Default Route开发者_如何转开发=>Desired Route

I am trying to create custom "RESTful" routes for the following default routes:

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

I want to keep the default routes, but improve the previous default routes to improve the readability. What should my routes look like to achieve this? This is what I have so far, but they are conflicting with each other so I know they aren't working right.

$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')));


By changing the order that I added the routes (moved the static route to the end), it fixed the conflict. However, I'm not sure if this is the best way to do this.

$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')));
0

精彩评论

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