- 设置cookie:
$cookie = new CHttpCookie('mycookie','this is my cookie');
$cookie->expire = time()+60*60*24*30; //有限期30天
Yii::app()->request->cookies['mycookie']=$cookie;
- 读取cookie:
$cookie = Yii::app()->request->getCookies();
echo $cookie['mycookie']->value;
- 销毁cookie:
$cookie = Yii::app()->request->getCookies();
unset($cookie[$name]);
- 获取更新的数据 id
$post->save();
$id = $post->attributes['id'];
- 获取插入的数据 id
$id = Yii::app()->db->getLastInsertID();
- 获取get,post过来的数据
Yii::app()->request->getParam('id');
- 获取ip地址
Yii::app()->request->userHostAddress;
- 获得上一页的url以返回
Yii::app()->request->urlReferrer;
- 得到当前url :
Yii::app()->request->url;
- 得到当前home url :
Yii::app()->homeUrl;
- 得到当前return url :
Yii::app()->user->returnUrl;
- 项目路径 :
dirname(Yii::app()->BasePath);
- 项目目录 :
Yii::app()->request->baseUrl;
- 在view中得到当前controller的ID方法:
Yii::app()->request->baseUrl;
- 在view中得到当前action的ID方法 :
Yii::app()->getController()->getAction()->id;
- yii判断提交方式 :
Yii::app()->request->isPostRequest;
- 得到当前域名:
Yii::app()->request->hostInfo;
- 得到proteced目录的物理路径:
YII::app()->basePath;