Symfony2 Session Usage Example Analysis _php instance

Source: Internet
Author: User
This paper analyzes the usage of SYMFONY2 session. Share to everyone for your reference, as follows:

Symfony from the method with the session, previous old 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 session's use of the method becomes

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 is from IT985 blog, please indicate the source and corresponding link when reproduced.

Read more about PHP framework related content Readers can view this site: "PHP Excellent Development Framework Summary", "CodeIgniter Introductory Tutorial", "CI (codeigniter) Framework Advanced Tutorial", "Yii framework Introduction and common skills Summary" and " thinkphp Getting Started Tutorial "

It is hoped that this article is helpful to 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: info-contact@alibabacloud.com 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.