Session

Symfony2's sessions are based on the native PHP session.

The session object can be retrieved in a controller via the request object: $session = $this->getRequest->getSession;

A session value can be set via the setAttribute method of the session object:

$session->set('foo', 'bar');

And can be retrieved via the getter of the session object:

$foo = $session->get('foo');

Flash session variables
These are normal session stored values, but with a twist. You do not have to recall to clear them from the session when they are no longer needed, because Symfony2 does it for you. A flash session variable is automatically cleared from the session on the next request (i.e. a flash session value has a "lifetime of 1 request").

A flash var can be set: $this->get('session')->setFlash('notice', 'Your changes were saved!');

and retrieved: $view['session']->getFlash('notice')