Getting base URL in Yii 2
Asked 07 September, 2021
Viewed 2.9K times
  • 66
Votes

I am trying to get the base URL for the project in Yii 2 but it doesn't seem to work. According to this page you used to be able to do:

Yii::app()->getBaseUrl(true);

In Yii 1, but it seems that that method in Yii 2 no longer accepts a parameter?

I've tried doing it without true, such as:

Yii::$app->getBaseUrl();

But it just returns empty.

How can you do this in Yii 2?

10 Answer