Symfony2 session and Cookie usage summary, Symfony2cookie
This article describes the session and cookie usage of Symfony2. Share to everyone for your reference, as follows:
Session Operation:
1. Set Session:
Public Function testsetsession () { $session = $this->getrequest ()->getsession (); $session->set ($sessionName, $sessionValue);}
2. Get Session:
Public Function testgetsession () {$session = $this->getrequest ()->getsession (); $username = $session->get ($ sessionname);}
3. Clear Session:
Public Function testclearsession () { $session = $this->getrequest ()->getsession ();//clear Session $ Session->clear ();}
Cookie operation:
1. Set Cookie
Use Symfony\component\httpfoundation\response;use symfony\component\httpfoundation\cookie;public function Testsetcookie ($name, $value, $expire =0) {$response = new response (); $response->headers->setcookie (New Cookie ($ Name, $value, time () + $expire)); $response->send (); including Sendheaders (), Sendcontent ()}
2. Get Cookie:
Public Function Testgetcookie () {$request = $this->getrequest (); return $request->cookies->all ();}
3. Clear Cookie:
Public Function Testclearcookie () {$response = new response (); $response->headers->setcookie (New Cookie ($name, $ Value,-1)); $response->send ();}
4. Twig Template Invoke Cookie:
{{App.request.cookies.get (' Cookie_name ')}}
It is hoped that this article is helpful to the PHP program design based on Symfony framework.
Articles you may be interested in:
- Implementation method of Symfony2 Federated query
- Symfony2 Creating a Page instance
- Analysis of date usage in twig of symfony2.4
- Symfony2 a summary of how to achieve data acquisition from a database
- Symfony2 Framework Learning Notes Form usage
- Analysis of plugin format of Symfony2 learning notes
- Symfony2 Study Notes System routing
- Symfony2 study notes of the controller usage detailed
- Symfony2 Study Notes Template usage detailed
- Symfony2 installing a third-party bundles instance
- An example analysis of Symfony2 function usage
http://www.bkjia.com/PHPjc/1111905.html www.bkjia.com true http://www.bkjia.com/PHPjc/1111905.html techarticle Symfony2 session and Cookie Usage Summary, Symfony2cookie This example describes the Symfony2 session and cookie usage. Share to everyone for reference, as follows: Session operation: ...