2011-10-31 89 views
2

所以我設置了路由器Zend的路由器任意路徑

protected function _initRoutes(){ 
     $front = Zend_Controller_Front::getInstance(); 
     $router = $front->getRouter(); 
     $routerInfo = array('action' => 'theaction', 
          'controller' => 'thecontroller',); 
     $route = new Zend_Controller_Router_Route(
         'some/path', 
         $routerInfo 
     ); 
     $router->addRoute('some/path', $route); 

     return $router; 
    } 

所以控制器「一些」和行動「路徑」實際上並不存在。相反,當用戶去/某些/路徑,它應該重定向到'theaction/thecontroller',而不是...

我的問題是...我如何設置它,以便我可以接受的abitrary數例如,我想讓/ some/path/other/param也重定向到相同的頁面...所以只要路徑的第一部分是/ some/path,不管以下我希望他們都重定向到相同的控制器和動作

我知道你可以做/some/path/*/* ....但只有在/ some/path之後只有2個其他路徑項時才能工作。 ...我想這個工作的任意數量的參數....所以/一些/路徑/參數1 /值1 /參數2 /值2 /參數3 /值3也應該工作,它會像用戶輸入contcon米勒/ theaction /參數1 /值1 /參數2 /值2 /參數3/valu3 ...

回答

1

您只需使用一個星號,如

$route = new Zend_Controller_Router_Route(
    'some/path/*', 
    array(
     'action'  => 'theaction', 
     'controller' => 'thecontroller', 
     'module'  => 'default' 
    ) 
); 

// can't say for sure but a slash in the route name is probably a bad idea 
// try a hyphen instead 
$router->addRoute('some-path', $route); 

看到這裏的第三個例子 - http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.standard

僅供參考,請勿在Bootstrap方法中獲得類似FrontController的資源。用這個代替...

$this->bootstrap('FrontController'); 
$front = $this->getResource('FrontController');