我有以下路线:
$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));
我希望能够为此路线添加可选参数'filter'。所以我可以使用以下网址:
http://example.org/default/list/filter/all/lname/asc/1 要么 http://example.org/default/list/lname/asc/ 要么 http://example.org/default/list/filter/all
任何一个都应该工作。我试图在Route中放置一个可选参数但是没有用。有什么想法吗?
答案 0 :(得分:12)
通常,在Zend的路由器中,与PHP一样,可选参数是具有默认值的参数。为filter
参数添加一个:
$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+'
)
);