mrateb
mrateb

Reputation: 2499

Yii2 - Alias common in web and console app

In one of my mail views I'm using the image with the following path

Yii::getAlias('@web/img/default.png');

This worked fine, but then I had to move running sending the mail from app to commands. When I did this I got the error

Invalid path alias: @web/img/default.png. 

From research, I understood that this happens because web/index.php is the place where the alias is pre-loaded, and naturally this file is not accessing when running a command. I'm at loss though as what path should I use as an alternative that would work in console and web apps.

Upvotes: 0

Views: 904

Answers (1)

Bizley
Bizley

Reputation: 18021

As it is stated in Aliases Guide:

Note: @web and @webroot aliases as their descriptions indicate are defined within Web application and therefore are not available for Console application by default.

You can create your own alias or use one of console-available ones like @app or @runtime.

Upvotes: 2

Related Questions