How to get root directory in yii2

后端 未结 7 1899
闹比i
闹比i 2020-12-15 03:20

yii2 Question

My yii2 install in d:\\wamp\\www\\yii2store

I want to get above path to save images which will be uploaded by me

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-15 03:48

    If you want to get the root directory of your yii2 project use, assuming that the name of your project is project_app you'll need to use:

    echo Yii::getAlias('@app');
    

    on windows you'd see "C:\dir\to\project_app"

    on linux you'll get "/var/www/dir/to/your/project_app"

    I was formally using:

    echo Yii::getAlias('@webroot').'/..';
    

    I hope this helps someone

提交回复
热议问题