Home > Backend Development > PHP Tutorial > Symfony2 session usage example analysis, symfony2 example analysis_PHP tutorial

Symfony2 session usage example analysis, symfony2 example analysis_PHP tutorial

WBOY
Release: 2016-07-12 08:59:28
Original
815 people have browsed it

Symfony2 session usage example analysis, symfony2 example analysis

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');

Copy after login

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());
}

Copy after login

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.

Articles you may be interested in:

  • Symfony2’s method of implementing built-in data in doctrine
  • Detailed explanation of installing third-party Bundles instances in Symfony2
  • Symfony2 usage chapter Detailed explanation of the image upload example made by the third-party library Upload
  • Graphic tutorial on the configuration method of Symfony2 under Nginx
  • Symfony2 installation method (2 methods)
  • High-performance PHP framework Symfony2 Classic introductory tutorial
  • Ten-minute introductory classic tutorial for learning Symfony
  • Symfony data verification method example analysis
  • Symfony form and page implementation skills
  • Symfony2 development Controller usage example analysis

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1098968.htmlTechArticleSymfony2 session usage example analysis, symfony2 example analysis This article analyzes the Symfony2 session usage through examples. Share it with everyone for your reference, the details are as follows: Symfony has its own session method...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template