Question

In my admin module, in the index controller i have multiple filtering options. The filtering is pretty simple done, based on the parameters, ie:

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.

Then in my application bootstrap I have built the route like this:

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

The thing is that i don't know how to combine all these parameters but also to make them optional. For example i wan't to have links like this:

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

or...

http://www.site.com/admin/pages/category/cars/status/published
Was it helpful?

Solution

Try this:

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

The * gets it to match variables as key/value pairs. So your example URL of http://www.example.com/admin/pages/by/date_added/order/asc/category/cars should match, and would have the route params by, order and category with the values from the URL. (Accessible from your controller via. $this->_getParam('order') an so on.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top