Service to manage PHP sessions (Symfony2)

0

I need to create a Service in PHP to manage the sessions of an application, does anyone have a practical example for this?

PS: I'm a beginner! :)

    
asked by anonymous 16.07.2015 / 22:53

1 answer

0

You do not need to create a service to manage sessions in Symfony applications, since it already has a built-in service for that purpose called session .

If you want to use 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 (through the constructor), just pass this same session on the service definition:

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

Got it? :)

    
17.07.2015 / 01:58