且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

yii2如何获取根目录

更新时间:2023-11-26 10:23:46

打开文件D:wampwwwyiistore2commonconfigparams-local.php

在返回之前粘贴下面的代码

Paste below code before return

Yii::setAlias('@anyname', realpath(dirname(__FILE__).'/../../'));

在 params-local.php 文件中插入上述代码后,您的文件应如下所示.

After inserting above code in params-local.php file your file should look like this.

Yii::setAlias('@anyname', realpath(dirname(__FILE__).'/../../'));

return [
];

现在要获取根目录的路径(在我的例子中是 D:wampwwwyiistore2)目录,您可以在任何 php 文件中使用以下代码.

Now to get path of your root (in my case its D:wampwwwyiistore2) directory you can use below code in any php file.

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