Reputation: 1451
I tried doing this:
$session->remove();
Also this:
$session->clear();
But it gives following error:
Call to a member function clear() on a non-object
Upvotes: 3
Views: 9296
Reputation: 15656
invalidate()
Clears all session data and regenerates session ID. Do not use session_destroy().
This actually does what you want.
Source & more info: http://symfony.com/doc/current/components/http_foundation/sessions.html
Also such things are easy to check by simply review the source.
For this case you should check Session
or SessionInterface
source:
http://api.symfony.com/2.6/Symfony/Component/HttpFoundation/Session/SessionInterface.html
http://api.symfony.com/2.6/Symfony/Component/HttpFoundation/Session/Session.html
Edit.
Of course this method belongs to Session
class so you have to access Session
object first in your controller.
So we go to:
http://symfony.com/doc/current/book/controller.html#managing-the-session
and we see how to do that:
public function indexAction(Request $request)
{
$session = $request->getSession();
$session->invalidate(); //here we can now clear the session.
}
Upvotes: 4