加载中...

Yii-编程- 常用调用收集


  1. 设置cookie:
    1. $cookie = new CHttpCookie('mycookie','this is my cookie');
    2. $cookie->expire = time()+60*60*24*30; //有限期30天
    3. Yii::app()->request->cookies['mycookie']=$cookie;

  2. 读取cookie:
    1. $cookie = Yii::app()->request->getCookies();
    2. echo $cookie['mycookie']->value;

  3. 销毁cookie:
    1. $cookie = Yii::app()->request->getCookies();
    2. unset($cookie[$name]);

  4. 获取更新的数据 id
    1. $post->save();
    2. $id = $post->attributes['id'];

  5. 获取插入的数据 id
    1. $id = Yii::app()->db->getLastInsertID();

  6. 获取get,post过来的数据
    1. Yii::app()->request->getParam('id');

  7. 获取ip地址
    1. Yii::app()->request->userHostAddress;

  8. 获得上一页的url以返回
    1. Yii::app()->request->urlReferrer;

  9. 得到当前url :
    1. Yii::app()->request->url;

  10. 得到当前home url :
    1. Yii::app()->homeUrl;

  11. 得到当前return url :
    1. Yii::app()->user->returnUrl;

  12. 项目路径 :
    1. dirname(Yii::app()->BasePath);

  13. 项目目录 :
    1. Yii::app()->request->baseUrl;

  14. 在view中得到当前controller的ID方法:
    1. Yii::app()->request->baseUrl;

  15. 在view中得到当前action的ID方法 :
    1. Yii::app()->getController()->getAction()->id;

  16. yii判断提交方式 :
    1. Yii::app()->request->isPostRequest;

  17. 得到当前域名: 
    1. Yii::app()->request->hostInfo;

  18. 得到proteced目录的物理路径:
    1. YII::app()->basePath;



还没有评论.