I know logout action can be performed by symfony2 security controller by default. when we give the path Logout like this it works fine.
but I need to perform some action like storing some data into the database when logout is happened.So how can i achieve this thing.
If any have an idea please help me.
you need to define new rule for logout action in routing.yml or annotation (it`s up to you)
logout_user:
    pattern:  /logoutUser
    defaults: { _controller: YourBundle:YourController:logout }
Then it`s only writing code for this action like this:
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'));
    }
There is also way to do the job proposed by tesmojones here symfony2 logout
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With