Home > Article > Backend Development > Symfony2 session usage example analysis, symfony2 example analysis_PHP tutorial
This article analyzes the Symfony2 session usage example. Share it with everyone for your reference, the details are as follows:
Symfony has its own session method. In the old version 2.2 and earlier, the session usage was
$session = $this->getRequest()->getSession(); $session->set('foo', 'bar'); $foobar = $session->get('foobar');
Later, the $this->getRequest() method was abandoned starting from Symfony2.3, and the usage method of session became
use Symfony\Component\HttpFoundation\Request; public function indexAction(Request $request) { $session = $request->getSession(); // store an attribute 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()); }
Permanent address of this article: http://blog.it985.com/13586.html
This article comes from IT985 blog. Please indicate the source and corresponding link when reprinting.
Readers who are interested in more content related to the PHP framework can check out the special topics of this site: "Summary of PHP Excellent Development Framework", "Introduction Tutorial on Codeigniter", "Advanced Tutorial on CI (CodeIgniter) Framework", "Introduction to Yii Framework and Summary of common techniques" and "ThinkPHP introductory tutorial"
I hope this article will be helpful to everyone’s PHP program design based on the Symfony framework.