yii 获取系统级请求参数的常用方法

1、GET/POST
 
1.1、获取GET/POST过来的数据
 
Yii::app()->request->getParam('id');
 
1.2、判断数据提交方式
    
Yii::app()->request->isPostRequest
2、session/cookie
 
2.1、session常用操作
 
$_SESSION 等价于 Yii::app()->session;
 
2.1.1、写入session
 
//启动session
$session=new CHttpSession;
$session->open();
    
Yii::app()->session['key'] = 'value'
 
2.1.2、读取session
    
Yii::app()->session['key']
 
2.1.3、获取session的ID
    
Yii::app()->session->sessionID
 
2.1.4、销毁session
    
//移去所有session变量
Yii::app()->session->clear();
//移去存储在服务器端的数据
Yii::app()->session->destroy();
 
2.1.5、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]);

 

posted on 2014-09-05 22:03  imxiu  阅读(374)  评论(0编辑  收藏  举报

导航