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