是否可以在控制器内使用重定向到的路由ID?
例如,我预定义了登录和注销URL的id登录和注销。在我的控制器中,我确定用户需要注销,我可以使用路由id将他们重定向到那个路由吗?
靴带
$router->addRoute('logout',new Zend_Controller_Router_Route('logout', array('module' => 'user', 'controller' => 'index', 'action' => 'logout')));
$router->addRoute('login', new Zend_Controller_Router_Route('login', array('module' => 'user', 'controller' => 'index', 'action' => 'login')));控制器
return $this->_redirect('login');目前,上面的方法无法工作,Id必须使用/login (也就是路由的基本URL )。
发布于 2012-08-31 21:04:22
我最近也有一个类似的要求,我解决的方法是使用路由器来组装url,然后执行重定向。
$redirectUrl = Zend_Controller_Front::getInstance()->getRouter()->assemble($userParams, $routeName);
$this->_redirect($redirectUrl);参见接口::汇编语言
发布于 2012-08-31 14:10:44
来自Zend框架1.8
$route = new Zend_Controller_Router_Route(
'index/:ident',
array(
'module' => 'user'
'controller' => 'index',
'action' => 'login'
),
array(
// match only digits
'ident' => '\d+'
)
);https://stackoverflow.com/questions/12216699
复制相似问题