1、GET/POST
1.1、获取GET/POST过来的数据
1
|
Yii::app()->request->getParam(
'id'
);
|
1.2、判断数据提交方式
1
|
Yii::app()->request->isPostRequest
|
2、session/cookie
2.1、session常用操作
$_SESSION 等价于 Yii::app()->session;
2.1.1、写入session
//启动session
$session=new CHttpSession;
$session->open();
1
|
Yii::app()->session[
'key'
] =
'value'
|
2.1.2、读取session
1
|
Yii::app()->session[
'key'
]
|
2.1.3、获取session的ID
1
|
Yii::app()->session->sessionID
|
2.1.4、销毁session
1
2
3
4
|
//移去所有session变量
Yii::app()->session->clear();
//移去存储在服务器端的数据
Yii::app()->session->destroy();
|
2.1.5、session高级用法
1
2
3
|
$session
= Yii::app()->session;
$session
[
'key'
] =
'value'
;
var_dump(
$session
[
'key'
]);
|
2.2 cookie
2.2.1 设置cookie
1
2
3
|
$cookie
=
new
CHttpCookie(‘mycookie’,'this is my cookie’);
$cookie
->expire = time()+60*60*24*30;
//有限期30天
Yii::app()->request->cookies[
'mycookie'
]=
$cookie
;
|
2.2.2 读取cookie
1
2
|
$cookie
= Yii::app()->request->getCookies();
echo
$cookie
[
'mycookie'
]->value;
|
2.2.3 销毁cookie
1
2
|
$cookie
= Yii::app()->request->getCookies();
unset(
$cookie
[
$name
]);
|
原文地址http://www.cnblogs.com/fengzhiqiangcaisangzi/p/3323431.html