How to set and get Session in Symfony2?

devquora
devquora

Posted On: Apr 22, 2024

 

SessionInterface object set and get method is used to set and get sessions in Symfony2.Below look below example:


public function sessionAction(SessionInterface $session)
{
    // store an attribute for reuse during a later user request
    $session->set('user_id', 5);

    // get the attribute set by another controller in another request
    $user_id = $session->get('user_id');  
}

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Symfony Interview Questions

    What is Symfony?

    Symfony is a set of PHP Components and leading PHP framework to create websites and dynamic web applications.It follows..

    Symfony Interview Questions

    Is Symfony is open sourced Framework?

    Yes, Symfony is open sourced Framework released under the MIT License. You can download it free from https://symfony.com..

    Symfony Interview Questions

    What is the latest version of Symfony?List server requirements to install it?

    Symfony 3.4 is the latest version of Symfony.To install and run Symfony 3, your server must fulfill following requirements..