Service to manage PHP sessions (Symfony2)

Asked

Viewed 117 times

0

I need to create a PHP Service to manage the Sessions of an application, someone has a practical example for this?

PS: I am a beginner! :)

1 answer

0


It is not necessary to create a service to manage sessions in Symfony applications, since it already has a built-in service for this purpose, called session.

If you want to use the session in your controllers, just call it by service id:

$this->get('session');

... or use the method getSession() of Symfony\Bundle\FrameworkBundle\Controller\Controller:

$this->getSession();

If you want to create a service and inject the session into it (via the constructor), just pass this one session in the definition of the service:

service:
    class: AppBundle\Service\MyService
    arguments: [ @session ]

Got it? :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.