How to set up and destroy sessions in PHP Symfony

How to establish and destroy a session on the controller side?
I tried to the side of view, it works fine. But now it is necessary from within the controller.

+4
source share
4 answers

I finally found a solution here. Use the "session" service described here: Old post

0
source

UPDATE:

Destroy a session in Symfony 2 as follows:

$request->getSession()->invalidate(1); 

As invalid, robs the current session intact, if you do not provide any parameter, you need to set the life expectancy to 1 (one second)

Symfony 3.4 documentation: http://api.symfony.com/3.4/Symfony/Component/HttpFoundation/Session/Session.html#method_invalidate

+3
source

Have you tried

 /** @var $session Session */ $session = $request->getSession(); $session->remove('name'); 
+1
source

You tried

 $this->getAttributeHolder()->remove('foo'); 

if it was saved in the foobar namespace

$ user-> getAttributeHolder () → delete ('Foobar', '', 'Foo');

0
source

All Articles