Andrew
Andrew

Reputation: 239097

Zend Framework: How to resolve these conflicting custom routes?

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

Upvotes: 2

Views: 306

Answers (1)

Andrew
Andrew

Reputation: 239097

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

Upvotes: 2

Related Questions