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!

Arthur
  • 3,253
  • 7
  • 43
  • 75
  • 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. – SiZE Dec 16 '16 at 05:38
  • Hope this link helps you http://stackoverflow.com/questions/31504980/php-adding-custom-namespace-using-autoloader-from-composer or join our russian yii community for more details as it very huge topic. – SiZE Dec 16 '16 at 05:41

0 Answers0