Reputation: 5830
How to set and destroy a session on the controller side?
Tried in the view side, works just fine. But now need it from inside the controller.
Upvotes: 4
Views: 9149
Reputation: 381
UPDATE:
Destroy a Session in Symfony 2 as follows:
$request->getSession()->invalidate(1);
As invalidate leaves the current session untouched if you are not providing any parameter you have to set the lifetime on 1 (one second)
Symfony 3.4 documentation: http://api.symfony.com/3.4/Symfony/Component/HttpFoundation/Session/Session.html#method_invalidate
Upvotes: 3
Reputation: 1167
Did you try?
/** @var $session Session */
$session = $request->getSession();
$session->remove('name');
Upvotes: 1
Reputation: 5830
At last I found the solution just here around. Use the "session" service explained here: Old post
Upvotes: 0
Reputation: 3136
Did you try
$this->getAttributeHolder()->remove('foo');
if it was saved in namespace foobar
$user->getAttributeHolder()->remove('foobar','','foo');
Upvotes: 0