160317 Yiihost信息获取

  • 假设域名为

    http://www.bee.com/index.php?r=plan/index
    
  • 获取域名

    Yii::app()->request->hostInfo;
    http://www.bee.com
    
  • 获取当前URL

    Yii::app()->request->getUrl();
    /index.php?r=/plan/index
    
  • 获取(除域名外的)首页地址

    Yii::app()->user->returnUrl;
    /
    
  • 获取(除域名外的)根目录地址

    Yii::app()->homeUrl;
    /index.php
    
  • 获取请求的相对路径

    Yii::app()->request->baseUrl;
    
  • 获取网站根目录相对地址

    Yii::app()->baseUrl;
    
  • Yii获取IP地址

    Yii::app()->request->userHostAddress;
    127.0.0.1
    
  • Yii判断提交方式

    Yii::app()->request-isPostRequest
    
  • proteced目录的物理路径

    Yii::app()->basePath;
    /Users/aj/Bee/protected
    
  • 获取上一页的url以返回

    Yii::app()->request->urlReferrer;
    
  • 获取当前控制器ID

    Yii::app()->getController()->getAction()->id;
    plan
    
  • 项目路径

    dirname(Yii::app()->BasePath);
    /Users/aj/Bee/
    
  • Yii获取get,post过来的数据

    Yii::app()->request->getParam('id');
    
  • Yii如何设置时区

    可以在config/main.php里'timeZone'=>'Asia/Chongqing',设定时区
    
  • 防止重复提交

    Ccontroler->refresh();
    
  • demo代码

    echo "获取域名";
    echo PHP_EOL;
    echo "Yii::app()->request->hostInfo;";
    echo PHP_EOL;
    echo Yii::app()->request->hostInfo;
    echo PHP_EOL;
    echo "获取当前URL";
    echo PHP_EOL;
    echo "Yii::app()->request->getUrl();";
    echo Yii::app()->request->getUrl();
    echo PHP_EOL;
    echo "获取(除域名外的)首页地址";
    echo PHP_EOL;
    echo "Yii::app()->user->returnUrl;";
    echo PHP_EOL;
    echo Yii::app()->user->returnUrl;
    echo PHP_EOL;
    echo "获取(除域名外的)根目录地址";
    echo PHP_EOL;
    echo "Yii::app()->homeUrl;";
    echo PHP_EOL;
    echo Yii::app()->homeUrl;
    echo PHP_EOL;
    echo "获取请求的相对路径";
    echo PHP_EOL;
    echo "Yii::app()->request->baseUrl;";
    echo PHP_EOL;
    echo Yii::app()->request->baseUrl;
    echo PHP_EOL;
    echo "获取网站根目录相对地址";
    echo PHP_EOL;
    echo "Yii::app()->baseUrl;";
    echo PHP_EOL;
    echo Yii::app()->baseUrl;
    echo PHP_EOL;
    echo "YII获取 IP地址";
    echo PHP_EOL;
    echo "Yii::app()->request->userHostAddress;";
    echo PHP_EOL;
    echo Yii::app()->request->userHostAddress;
    echo PHP_EOL;
    echo "Yii判断提交方式";
    echo PHP_EOL;
    echo "Yii::app()->request-isPostRequest";
    echo PHP_EOL;
    echo "proteced目录的物理路径";
    echo PHP_EOL;
    echo "Yii::app()->basePath;";
    echo PHP_EOL;
    echo Yii::app()->basePath;
    echo PHP_EOL;
    echo "获取上一页的url以返回";
    echo PHP_EOL;
    echo "Yii::app()->request->urlReferrer;";
    echo PHP_EOL;
    echo Yii::app()->request->urlReferrer;
    echo PHP_EOL;
    echo "获取当前控制器ID";
    echo PHP_EOL;
    echo "Yii::app()->getController()->getAction()->id;";
    echo PHP_EOL;
    echo Yii::app()->getController()->getAction()->id;
    echo PHP_EOL;
    echo "项目路径";
    echo PHP_EOL;
    echo "dirname(Yii::app()->BasePath);";
    echo PHP_EOL;
    echo dirname(Yii::app()->BasePath);
    echo PHP_EOL;
    echo "Yii获取get,post过来的数据";
    echo PHP_EOL;
    echo "Yii::app()->request->getParam('id');";
    echo PHP_EOL;
    echo Yii::app()->request->getParam('id');
    echo PHP_EOL;
    echo "Yii如何设置时区";
    echo PHP_EOL;
    echo "可以在config/main.php里'timeZone'=>'Asia/Chongqing',设定时区";
    echo PHP_EOL;
    echo "防止重复提交";
    echo PHP_EOL;
    echo "Ccontroler->refresh();";
    

发表评论

电子邮件地址不会被公开。 必填项已用*标注