This article analyzes the Symfony2 session usage. Share to everyone for your reference, specific as follows:
Symfony from the method of session, previous version 2.2 and previous session usage is
$session = $this->getrequest ()->getsession ();
$session->set (' foo ', ' Bar ');
$foobar = $session->get (' Foobar ');
Later Symfony2.3 began to $this->getrequest () method was discarded, the use of the session has become
Use Symfony\component\httpfoundation\request;
Public Function indexaction (Request $request)
{
$session = $request->getsession ();
Store an attributes for reuse during a later user request
$session->set (' foo ', ' Bar ');
Get the attribute set by another controller in another request
$foobar = $session->get (' Foobar ');
Use a default value if the attribute doesn ' t exist
$filters = $session->get (' Filters ', array ());
}
This article permanent address:http://blog.it985.com/13586.html
This article comes from IT985 blog, reprint, please indicate the source and corresponding link.
For more information about PHP framework interested readers can view the site topics: "PHP Excellent Development Framework Summary", "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "Yii framework Introduction and common skills Summary" and " thinkphp Getting Started Tutorial "
I hope this article will help you with the PHP program design based on Symfony framework.