2014-07-08 16 views
0

在我的引導文件中,我有以下路由鏈。期望的行爲是通過/usa/:controller/:action發送任何請求到本地模塊。 例如,當調用http://{hostname}/usa/index/index時,請求會通過本地模塊,索引控制器,索引操作。無法使用Zend路由鏈獲取參數

我遇到的問題是添加參數。舉例來說,當我要求http://{hostname}/usa/index/index/id/5來嘗試獲得id參數,我收到以下錯誤信息: An Error occurred. Page not found. Exception information: Message: Invalid controller specified (usa)具有以下請求參數:

array (
'controller' => 'usa', 
'action' => 'index', 
'id' => '5', 
'module' => 'default', 
) 

我怎樣才能建立連鎖路由爲了仍可利用其他參數?

這是我在應用程序引導代碼:

protected function _initRouting(){ 
    $router = Zend_Controller_Front::getInstance()->getRouter(); // Get the main router from the front controller. 
    $router->addDefaultRoutes(); // Don't forget default routes! 

    //get default local route (directs to the local module) 
    $defaultLocalRoute = new Zend_Controller_Router_Route(
     '/:controller/:action', 
     array(
       'module' => 'local', 
       'controller' => 'index', 
       'action' => 'index' 
     ) 
); 

    $regionRoute = new Zend_Controller_Router_Route(
    '/usa/', 
    array('region' => 'usa') 
); 

    //chain this region route to the default local route that directs to the local module 
    $fullRegionRoute = $regionRoute->chain($defaultLocalRoute); 
    //add the full route to the router (ie. hamiltonRoute, atlanticcaRoute) 
    $regionRouteName = 'usaRoute'; 
    $router->addRoute($regionRouteName, $fullRegionRoute); 
} 

回答

0

添加*$defaultLocalRoute結束時能夠解決這個問題對我來說。

//get default local route (directs to the local module) 
$defaultLocalRoute = new Zend_Controller_Router_Route(
    '/:controller/:action/*', 
    array(
      'module' => 'local', 
      'controller' => 'index', 
      'action' => 'index' 
    ) 
); 

現在要http://{hostname}/usa/product/view/id/5的情況下,請求轉到所需的位置 - >

module:  'local', 
controller: 'product', 
action:  'view', 
params:  array('id'=>5)