Symfony2 Session Usage Example Analysis _php instance

Source: Internet
Author: User
Tags php framework codeigniter

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:
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.