【问题标题】:How to override logout action in symfony2如何覆盖 symfony2 中的注销操作
【发布时间】:2013-01-26 06:34:06
【问题描述】:

我知道 symfony2 安全控制器默认可以执行注销操作。 当我们像这样给出路径 Logout 时,它工作正常。

但是当注销发生时我需要执行一些操作,例如将一些数据存储到数据库中。那么我该如何实现呢。

如果有任何想法,请帮助我。

【问题讨论】:

标签: php symfony


【解决方案1】:

您需要在 routing.yml 或注释中为注销操作定义新规则(由您决定)

logout_user:
    pattern:  /logoutUser
    defaults: { _controller: YourBundle:YourController:logout }

那么它只是像这样为这个动作编写代码:

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'));
    }

还有一种方法可以完成 tesmojones 提出的工作 这里symfony2 logout

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-27
    • 2012-09-26
    • 2020-11-12
    • 1970-01-01
    • 2012-07-12
    • 1970-01-01
    相关资源
    最近更新 更多