Introduction to the usage of Symfony2 session

不言
Release: 2023-04-02 09:44:02
Original
1777 people have browsed it

This article mainly introduces the usage of Symfony2 session, and analyzes the related usage skills of Symfony's own session method in the form of examples. Friends in need can refer to

This article analyzes the usage of Symfony2 session with examples. Share it with everyone for your reference, the details are as follows:

Symfony has its own session method. The session usage in the old version 2.2 and before was

$session = $this->getRequest()->getSession();
$session->set('foo', 'bar');
$foobar = $session->get('foobar');
Copy after login

Later, starting from Symfony2.3, the $this->getRequest() method was abandoned, 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

The above is this article The entire content, I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Introduction to php using parse_url and parse_str to parse URLs

##About the method of ThinkPHP returning JSON through AJAX

The above is the detailed content of Introduction to the usage of Symfony2 session. For more information, please follow other related articles on the PHP Chinese website!

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