Yii2 Application Baseurl

In Yii 1.1 there was


to get the url for the application. Is there any equivalent function in Yii2 (couldn’t find any in Yii2 Application class). Or do we need to use:


In Yii2 we have cool aliases feature.

If I’m not mistaken, what you’re looking for is @web

OK, then how to echo the base url in view (say in anchors href)?

echo Yii::getAlias('@web')

outputs current url (or nothing I guess).

1 Like

Is this what you need?


Yeah, that is exactly what I wanted. Missed it in source code (actually I was searching for something with words "baseurl" in it).

Let me also mention here for others, that there are also getter and setter methonds for it:

string getHomeUrl( )

void setHomeUrl( $value )

also Url::home();

You may also use: Url::base().