2011-11-18 109 views
0

假设下面的路由器:Zend_Controller_Router_Route的动态路由

$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/

朗==恩 类型==酒店

有可能以这样的方式,换做只有一种语言,例如德语,结果是http://example/Hotels/而不是http://example/de/Hotels/

坦克,

回答

0

从路线点的视图,只是沟郎参数只是有“类型”之一。

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

而且从控制器点,只是看空郎参数来定义默认的(在你的情况,DE)。

如果您的网页已被重定向到/德/酒店,然后在我们的控制器测试此:

if($lang == 'de' && $type == 'Hotels') { 
    $this->_redirect('/Hotels'); 
}