我要设置一个路由器
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;
}
所以控制器'some'和动作'path'并不存在。相反,当用户转到/some/路径时,它应该重定向到'theaction/thecontroller'而不是....
我的问题是……我如何设置它,以便我可以接受/some/path之后的任意数量的参数…例如,我希望/some/path/other/param也重定向到同一页面…所以只要路径的第一段是/some/path,不管后面是什么,我都希望它们都重定向到相同的控制器和动作我知道你可以做/some/path/*/*
....但这只会在/some/path.....之后只有2个其他路径项时才会起作用我想让它适用于任意数量的参数....所以/some/path/param1/value1/param2/value2/param3/value3也应该仍然工作,它会像用户键入控制器/theaction/param1/value1/param2/value2/param3/valu3…
您只需使用一个星号,例如
$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');