0

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
2
  • Any reason you're using a regex route rather than Zend_Controller_Router_Route, which supports this out of the box? Commented Oct 8, 2013 at 12:42
  • @TimFountain no, no reason. i actually am looking over framework.zend.com/manual/1.12/en/zend.controller.router.html exactly at the Zend_Controller_Router_Route example, but i can't figure it out. Commented Oct 8, 2013 at 12:44

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

yes, this works thank you. i managed in the end something similar with regex like this new Zend_Controller_Router_Route_Regex("^admin/pages/by/([a-z,_]+)/order/([a-z]+)(/status/(\w+))?$", but your solution is much simple and cleaner

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.