我知道默认情况下symfony2安全控制器可以执行注销操作.当我们像这样给出路径注销它工作正常.
但我需要执行一些操作,例如在注销时将一些数据存储到数据库中.那么我怎样才能实现这一点.
如果有任何想法请帮助我.
你需要在routing.yml或annotation中为logout动作定义新规则(由你决定)
logout_user:
pattern: /logoutUser
defaults: { _controller: YourBundle:YourController:logout }
Run Code Online (Sandbox Code Playgroud)
然后它只为这个动作编写代码,如下所示:
public function logoutAction() {
//do whatever you want here
//clear the token, cancel session and redirect
$this->get('security.context')->setToken(null);
$this->get('request')->getSession()->invalidate();
return $this->redirect($this->generateUrl('login'));
}
Run Code Online (Sandbox Code Playgroud)
还有办法在这里通过symfony2 logout来完成tesmojones提出的工作
归档时间: |
|
查看次数: |
5506 次 |
最近记录: |