国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

Symfony2之session與cookie用法小結

2024-05-04 23:44:12
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了Symfony2之session與cookie用法,結合實例形式總結分析了Symfony框架針對session與cookie的設置、獲取及刪除等操作的實現方法,需要的朋友可以參考下
 

本文實例講述了Symfony2之session與cookie用法。分享給大家供大家參考,具體如下:

session操作:

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();//清除session  $session->clear();}

cookie操作:

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(); // 包括 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模板調用cookie:

{{ app.request.cookies.get('cookie_name') }}

希望本文所述對大家基于Symfony框架的PHP程序設計有所幫助。



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 白河县| 江孜县| 祁阳县| 余江县| 静乐县| 黎川县| 安平县| 兰州市| 浪卡子县| 八宿县| 阿瓦提县| 库伦旗| 大港区| 新巴尔虎左旗| 合水县| 兰州市| 大洼县| 广德县| 石河子市| 汤阴县| 谢通门县| 巴塘县| 永修县| 岳池县| 昭觉县| 九龙县| 贵溪市| 宁晋县| 土默特左旗| 华坪县| 柳江县| 仁布县| 肇州县| 九龙城区| 博客| 定陶县| 疏附县| 甘德县| 弥勒县| 万盛区| 依兰县|