I'm trying to set up Zend pagination on my site so that I can use Paul Irish's jquery infinite scroll plugin, but I'm having trouble with my routes. I currently have these routes set up for my organizer page:
//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);
It matches organizer/index/popular
correctly in this order, but if I put a page number on it the filter suddenly comes up null. If I switch the order, organizer/index/popular/2
works perfectly fine but organizer/index/popular
no longer works. I could just only use the more specific route since that's the one I'll need for pagination, but I would like to include both to accommodate users trying to type the url or in case I forget to change the links somewhere in my code. Can I incorporate multiple routes to the same controller with Zend? If so, what am I doing wrong?
You need to give the routes different names. You've called them both 'organizer', so the second one replaces the first each time.
You could also easily do this with one route simply by setting a default value for the page variable:
$route = new Zend_Controller_Router_Route(
'organizer/index/:filter/:page',
array(
'controller'=> 'organizer',
'action'=> 'index',
'page' => 1
)
);
$router->addRoute('organizer', $route);