1.一、獲取GET/POST過來的數據服務器
1
|
Yii::app()->request->getParam(
'id'
);
|
1.二、判斷數據提交方式cookie
1
|
Yii::app()->request->isPostRequest
|
2.一、session經常使用操做session
$_SESSION 等價於 Yii::app()->session;app
2.1.一、寫入sessionthis
//啓動session
$session=new CHttpSession;
$session->open();spa
1
|
Yii::app()->session[
'key'
] =
'value'
|
2.1.二、讀取sessioncode
1
|
Yii::app()->session[
'key'
]
|
2.1.三、獲取session的IDci
1
|
Yii::app()->session->sessionID
|
2.1.四、銷燬sessionget
1
2
3
4
|
//移去全部session變量
Yii::app()->session->clear();
//移去存儲在服務器端的數據
Yii::app()->session->destroy();
|
2.1.五、session高級用法it
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
]);
|