Symfony2 & Sessions


To get the session in Symfony2 you call the “session” service (in this example, from inside a controller instance):

$session  = $this->get("session");

This will give you a Session object which you can then use to store session data. All the setXXX methods start the session if is not already, so you dont need to call $session->start() most of the time. This class uses inernally a NativeSessionStorage which wraps the classic $_SESSION object. There are other SessionStoreage objects, idk yet how to use them.

Advertisements