lilbiscuit lilbiscuit - 4 months ago 8
PHP Question

Yii2 web url without using setAlias

I have a Yii2 app but no ability to edit the config files to utilize setAlias.

If my domain is example.com, and my Yii application is in

/my-app
directory, then what would be the Yii command to return the following string:

http://example.com/my-app/


Yii::getAlias('@app')
returns

/httpdocs/my-app


Many posts exist but all I've found is suggestions either based on Yii1 or using setAlias in application config.

Answer

Yuo can use a simple urlHelper (for absolute url)

use yii\helpers\Url;


echo Url::to(['/'], true );
Comments