I have the following route:
$gridRoute = new Zend_Controller_Router_Route(
':module/:controller/list/:order/:dir/:page',
array (
'module' => 'default',
'controller' => 'index',
'order' => '',
'dir' => 'asc',
'page' => 1,
'action' => 'list'
),
array (
'page' => '\d+'
)
);
$router->addRoute('grid', $mainRoute->chain($gridRoute));
I would like to be able to add an optional parameter 'filter' to this route. So I could use the following url:
http://example.org/default/list/filter/all/lname/asc/1 or http://example.org/default/list/lname/asc/ or http://example.org/default/list/filter/all
Either one should work. I tried to place an optional parameter in the Route but that did not work. Any ideas?
Typically, in Zend's Router, like in PHP, an optional parameter is a parameter that has a default value. Add one for the filter
parameter:
$gridRoute = new Zend_Controller_Router_Route(
':module/:controller/list/:order/:dir/:page/:filter',
array (
'module' => 'default',
'controller' => 'index',
'order' => '',
'dir' => 'asc',
'page' => 1,
'action' => 'list',
'filter' => null, // define default for filter here
),
array (
'page' => '\d+'
)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With