how do I make Yii::getAlias('@webroot') work in console application

Yii2 console application needs to work with Yii::getAlias(’@webroot’). I get ‘Invalid path alias: @webroot

Looks like I can manually set "aliases" for console application.

Any ideas which files and how do I set aliases for Yii2 console application ?


maybe you could use ‘@app/web’

1 Like

Use this on your controller to set the alias

public function init()
    Yii::setAlias('@webroot', realpath(dirname(__FILE__).'/../'));

so Yii::getAlias(’@webroot’) will work