假设有以下路由器:
$router->addRoute('listOfFacilities',
new Zend_Controller_Router_Route('/:lang/:type/',
array('module' => 'default',
'controller' => 'search',
'action' => 'index',
'lang' => 'de',
'type' => ':type'
)));
结果将是: http://example/en/Hotels/
lang == en type == Hotels
可以这样做,只有一种语言,例如德语,结果是http://example/Hotels/而不是http://example/de/Hotels/?
坦克,
答案 0 :(得分:0)
从路线的角度来看,只需抛弃lang参数即可获得“类型”参数。
$router->addRoute('listOfFacilities',
new Zend_Controller_Router_Route('/:lang/:type/',
array('module' => 'default',
'controller' => 'search',
'action' => 'index',
'lang' => 'de',
'type' => ':type'
)));
$router->addRoute('listOfFacilities_default',
new Zend_Controller_Router_Route('/:type',
array('module' => 'default',
'controller' => 'search',
'action' => 'index',
'type' => ':type'
)));
从控制器的角度来看,只需查找一个空的lang参数来定义默认参数(在您的情况下为de)。
如果您的页面已经重定向到/ de / Hotels,那么在我们的控制器测试中:
if($lang == 'de' && $type == 'Hotels') {
$this->_redirect('/Hotels');
}