2014-07-08 2 views
0

В моем загрузочном файле у меня есть следующая цепочка маршрутизации. Желаемое поведение - отправить любой запрос через /usa/:controller/:action в локальный модуль. Например, когда вызывается http://{hostname}/usa/index/index, запрос проходит через локальный модуль, индексный контроллер, действие индекса.Невозможно получить параметры с помощью Zend Routing Chain

Проблема, которую я испытываю, заключается в добавлении параметров. Например, когда я прошу http://{hostname}/usa/index/index/id/5, чтобы попытаться получить параметр id, я получаю следующее сообщение об ошибке: An Error occurred. Page not found. Exception information: Message: Invalid controller specified (usa) со следующей Params запроса:

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)