2011-11-18 105 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'); 
}