yii系統路徑筆記

1、源代碼:

public function actionGetUrlList()
{
    echo "當前域名地址:".Yii::$app->request->hostInfo."<br>";
    echo "當前目錄物理路徑:".Yii::$app->basePath."<br>";  
    echo "當前項目路徑:".dirname(Yii::$app->BasePath)."<br>";
    echo "當前Url: ".Yii::$app->request->url."<br>";
    echo "當前Home Url: ".Yii::$app->homeUrl."<br>";
    echo "當前return Url: ".Yii::$app->user->returnUrl."<br>";
    echo "獲取當前模塊ID方法:".Yii::$app->controller->module->id."<br>";
    echo "獲取當前控制器的ID方法:".Yii::$app->controller->id."<br>";
    echo "獲取當前action的ID方法:".Yii::$app->controller->action->id."<br>";
    echo "ip地址: ".Yii::$app->request->userIP."<br>";
}

2、訪問路徑 http://localhost/visualization/backend/web/index.php?r=site/get-url-list 顯示如下: 顯示路徑.png

 

下面這些別名都是在Yii2裏面系統定義的,可以直接拿來就用
 

  • '@yii' =>
    •       '@yii/swiftmailer' => string 'C:\wamp\www\advanced\vendor/yiisoft/yii2-swiftmailer' (length=52)
    •       '@yii/gii' => string 'C:\wamp\www\advanced\vendor/yiisoft/yii2-gii' (length=44)
    •       '@yii/faker' => string 'C:\wamp\www\advanced\vendor/yiisoft/yii2-faker' (length=46)
    •       '@yii/debug' => string 'C:\wamp\www\advanced\vendor/yiisoft/yii2-debug' (length=46)
    •       '@yii/codeception' => string 'C:\wamp\www\advanced\vendor/yiisoft/yii2-codeception' (length=52)
    •       '@yii/bootstrap' => string 'C:\wamp\www\advanced\vendor/yiisoft/yii2-bootstrap' (length=50)
    •       '@yii' => string 'C:\wamp\www\advanced\vendor\yiisoft\yii2' (length=40)
  •   '@app' => string 'C:\wamp\www\advanced\frontend' (length=29)
  •   '@vendor' => string 'C:\wamp\www\advanced/vendor' (length=27)
  •   '@bower' => string 'C:\wamp\www\advanced/vendor\bower' (length=33)
  •   '@npm' => string 'C:\wamp\www\advanced/vendor\npm' (length=31)
  •   '@runtime' => string 'C:\wamp\www\advanced\frontend\runtime' (length=37)
  •   '@webroot' => string 'C:/wamp/www/advanced/frontend/web' (length=33)
  •   '@web' => string '/advanced/frontend/web' (length=22)


其中最常用的別名有

  • @app
  • @vendor
  • @runtime
  • @webroot
  • @web


而且可以看到除了@web別名是url外,其它的都是物理路徑

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章