Php 无法使用Zend路由链获取参数
在我的引导文件中,我有以下路由链。所需的行为是通过Php 无法使用Zend路由链获取参数,php,zend-framework,zend-route,Php,Zend Framework,Zend Route,在我的引导文件中,我有以下路由链。所需的行为是通过/usa/:controller/:action向本地模块发送任何请求。 例如,当调用http://{hostname}/usa/index/index时,请求通过本地模块、索引控制器、索引操作进行 我遇到的问题是添加参数。例如,当我请求http://{hostname}/usa/index/index/id/5尝试获取id参数时,我得到以下错误消息: 发生错误。找不到页面。异常信息:消息:使用以下请求参数指定的控制器无效(美国): array
/usa/:controller/:action
向本地模块发送任何请求。
例如,当调用http://{hostname}/usa/index/index
时,请求通过本地模块、索引控制器、索引操作进行
我遇到的问题是添加参数。例如,当我请求http://{hostname}/usa/index/index/id/5
尝试获取id
参数时,我得到以下错误消息:
发生错误。找不到页面。异常信息:消息:使用以下请求参数指定的控制器无效(美国)
:
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);
}
将
*
添加到$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)