一、GET/POST
1、获取GET/POST过来的数据
Yii::app()->request->getParam(‘id‘);
2、判断数据提交方式
Yii::app()->request->isPostRequest;
二、session/cookie
1、session常用操作
$_SESSION等价于Yii::app()->session;
1.1、写入session
//启动session $session = new ChttpSession; $session->open(); Yii::app()->session[‘key‘] = ‘value‘;
1.2、读取session
Yii::app()->session[‘key‘];
1.3、获取session的ID
Yii::app()->session->sessionID
1.4、销毁session
//移除所有的session变量 Yii::app()->session->clear(); //移除存储在服务器端的数据 Yii::app()->session->destroy();
2、cookie
2.1、设置cookie
$cookie = new CHttpCookie(‘mycookie‘, ‘this is my cookie‘); $cookie->expire = time() + 60*60*24*30; Yii::app()->request->cookie[‘mycookie‘] = $cookie;
2.2、读取cookie
$cookie = Yii::app()->request->getCookies(); echo $cookie[‘mycookie‘]->values;
2.3、销毁cookie
$cookie = Yii::app()->request->getCookies(); unset($cookie[$name]);
来源:http://my.oschina.net/jiangchike/blog/208696
时间: 2024-10-06 21:17:26