Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

yii2 Question

My yii2 install in d:wampwwwyii2store

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

I have pass all available arguments in Yii::getAlias('@webroot') (below are the lists of argument which I have used).

@yii - framework directory.

@app - base path of currently running application.

@runtime - runtime directory.

@vendor - Composer vendor directory.

@webroot - web root directory of currently running web application.

@web - base URL of currently running web application.

And also once I will get above path to save images then how can I get path something like this localhost/yiistore2/upload to be use in img tag src.

One more thing how can I create my own alias with Yii::setAlias() and where to create this so that I can load it on every controller.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
399 views
Welcome To Ask or Share your Answers For Others

1 Answer

Open file D:wampwwwyiistore2commonconfigparams-local.php

Paste below code before return

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

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

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

return [
];

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');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...