How to use Sessions in Symfony?

Like in classic PHP we use the magic variables to start and create sessions, so how to do that in Symfony?


In your controller, you can access session variables through the user object.

// Get a session value
$name = $this->getUser()->getAttribute('name', 'default_value');
// Set a session value
$this->getUser()->setAttribute('name', $value);

In Symfony2, the syntax is different:

$session = $this->getRequest()->getSession();

// store an attribute for reuse during a later user request
$session->set('foo', 'bar');

// in another controller for another request
$foo = $session->get('foo');

You can also get session variables from Twig, without having to pass the session variable explicitly (it's in the global 'app'):

{{ app.session.get('foo', 'bar'); }}

Need Your Help

WPF Slider AutoToolTip visible on hover

wpf wpf-controls

By default the AutoToolTip only shows up when the users click the thumb, but I want to be able to show it as soon as the mouse is over the thumb (without clicking). Is this possible?

Transform Properies in CSS

css css-transforms

I want to rotate an image when i hover on it.I use the follwing code to rotate.Bui it doesn't works....