Valeria Mori
Valeria Mori

Reputation: 23

webroot entire path in Yii2

I have some trouble with an Yii2 application. I need to put into a variabile the complete webroot path of my application, in my case www.mysite.it/language/catalogue/. When I call the function to retrieve this information, I get www.mysite.it/application/web where application/web is the root of my project.

I have tried this function:

$home = Yii::$app->request->getAbsoluteUrl();

It is any way to do what I want? Thanks in advance.

Upvotes: 0

Views: 1101

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133400

You should use yii\helpers\Url features

http://www.yiiframework.com/doc-2.0/yii-helpers-url.html

http://www.yiiframework.com/doc-2.0/guide-helper-url.html

and eg_ for home Url::home()

 $absoluteHomeUrl = Url::home(true);

or for Url:to()

 $url = Url::toRoute(['language/catalogue/']);

the use of the UrlHelpers prevent your code from different url result related to your urlManager config (with or without pretty url)

Upvotes: 1

Related Questions