在module.config.php中,我添加了:
'logout' => array(
'type' => 'literal',
'options' => array(
'route' => '/logout',
'defaults' => array(
'__NAMESPACE__' => 'Users\Controller',
'controller' => 'Index',
'action' => 'logout',
),
),
),
在IndexController.php中添加:
public function logoutAction() {
$this->getSessionStorage()->forgetMe();
$this->getAuthService()->getStorage()->clear("email");
return $this->redirect()->toRoute('users', array('controller' => 'Login', 'action' => 'index'));
}
并始终重定向到http:// localhost / users,但应重定向到http:// localhost / users / login / index
当您使用第Zend\Mvc\Controller\Plugin\Redirect::toRoute()
一个参数时,即是您在中定义的路由的名称module.config.php
。例如,您提到的路线定义为logout
。
'logout' => array(
'type' => 'literal',
'options' => array(
'route' => '/logout',
'defaults' => array(
'__NAMESPACE__' => 'Users\Controller',
'controller' => 'Index',
'action' => 'logout',
),
),
),
因此,要重定向到此路由,请使用以下行。
$this->redirect()->toRoute('logout')
无需将控制器和/或操作作为第二个参数提供,因为您已经options
在路由的处进行了配置。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句