0

I found, that in Yii 2 there is an interesting namespace app. For example,

use app\assets\AppAsset;

There http://www.yiiframework.com/doc-2.0/guide-concept-autoloading.html I found info

When using the Basic Project Template, you may put your classes under the top-level namespace app so that they can be autoloaded by Yii without the need of defining a new alias. This is because @app is a predefined alias, and a class name like app\components\MyClass can be resolved into the class file AppBasePath/components/MyClass.php, according to the algorithm just described.

Also I found http://www.yiiframework.com/doc-2.0/guide-concept-aliases.html#predefined-aliases

@app, the base path of the currently running application.

And, when I call

print_r(Yii::getAlias("@app"));die;

it's printing

/home/u1326jyq/domains/lifesim.biz/public_html/dev

Am I right or not, that namespace app is equal to /home/u1326jyq/domains/lifesim.biz/public_html/dev ?

But, if I trying to execute script like

use home\u1326jyq\domains\lifesim.biz\public_html\dev\assets\syntaxhighlighter\SyntaxhighlighterAsset;

SyntaxhighlighterAsset::register($this); 

it's fails with 500 error.

Where is definition of the app namespace in Yii2 and how to define custom myCustomApp namespace, that will be equal to my path /home/u1326jyq/domains/lifesim.biz/public_html/dev, to using it with code like

use myCustomApp\assets\syntaxhighlighter\SyntaxhighlighterAsset;

that must be equal to code

define('__ROOT__', dirname(dirname(__FILE__))); 
require_once(__ROOT__.'/assets/syntaxhighlighter/SyntaxhighlighterAsset'); 

? Thank you very much!

2
  • 2
    Namespace and alias is not the same. Alias is equal full path on server like /home/usr/var... and namespace is a shortcut for autoloader to find a class path. Commented Dec 16, 2016 at 5:38
  • Hope this link helps you stackoverflow.com/questions/31504980/… or join our russian yii community for more details as it very huge topic. Commented Dec 16, 2016 at 5:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.