You are viewing revision #7 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.
If you are coming over from Yii 1.x to Yii 2, and already read this guide, you may note that namespaces are very important in Yii 2 to identify classes. But do you know the list of seeded path aliases that come shipped with a basic or advanced app? Here is my attempt to list them.
Path Aliases List ¶
Yii2 Basic App ¶
@app
: Your application root directory@vendor
: Your vendor directory under@app
@runtime
: Your application files runtime/cache storage folder@web
: Your application base url path@webroot
: Your application web root@tests
: Your console tests directory
Yii2 Advanced App ¶
@app
: Your application root directory@vendor
: Your vendor directory under@app
@runtime
: Your application files runtime/cache storage folder@web
: Your application base url path@webroot
: Your application web root@tests
: Your console tests directory@common
: Alias for your common root folder under@app
@frontend
: Alias for your frontend root folder under@app
@backend
: Alias for your backend root folder under@app
@console
: Alias for your console root folder under@app
Nice summary, but
@app is not "application root directory" but current application's (frontend/backend/console) root directory in advanced template, this makes all subsequent "under @app" remarks incorrect. Was it the cause of these thumb-downs?
@webroot doesn't work in console
Using @webroot in the advanced app in a console command gives an 'invalid path alias: @webroot' error
@frontend not accesible from backend
@frontend always is marked as not found from backend.
Instead of this article see Predefined Aliases in documentation, it provides more correct and detailed information.
Yii 2 Advanced Project Template adds few extra aliases in common/config/bootstrap.php.
@webroot doesn't work in console application indeed, because application may have few tiers, for example frontend and backend, and @webroot's for these tiers are usually different, so it is unclear which one you want in console application. But you can define any extra aliases e.g. in console/config/bootstrap.php.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.