yii2 找到根目录的绝对路径


  1. 创建 components 在 common 文件加下
  2. 创建  Request.php

    namespace common\components;
    
    
    class Request extends \yii\web\Request {
        public $web;
        public $adminUrl;
    
        public function getBaseUrl(){
            return str_replace($this->web, "", parent::getBaseUrl()) . $this->adminUrl;
        }
    
        public function getActualBaseUrl(){
            return str_replace($this->web, "", parent::getBaseUrl());
        }
    
        public function resolvePathInfo(){
            if($this->getUrl() === $this->adminUrl){
                return "";
            }else{
                return parent::resolvePathInfo();
            }
        }
    }
    
  3. Yii::$app->request->getActualBaseUrl()

你可能感兴趣的:(php技术总结)