加载中...

Yii-编程- 常用调用收集


  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. 读取cookie:
    $cookie = Yii::app()->request->getCookies();  
    echo $cookie['mycookie']->value;  

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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



还没有评论.