All Yii (and vendor) classes are autoloded automatically, the “use” statements have nothing to do with autoloading. Unfortunately that’s the way PHP namespaces work. The only way to get rid of them is to declare your own classes in the global namespace extending framewok’s helper classes. I’m not sure if it’s worth the effort.
Sorry, my fault. I was not clear enough in my question.
Now, when i need to use e.g. the Html-Helper I need to load it over "use yii\helpers\Html;" in each view separatly.
This is a repeat in all my views. is there not an other solution for that? e.g. to say to the view component: everytime you are loaded, please load automaticly (without useing "use" in all the views) some classes.
It won’t solve your problem because “use” statements don’t actually “load” anything. They don’t even trigger the autoloading mehcanism. Their only purpose is to tell the PHP parser that which one of the possible classes is referred as “Html” in your code (is it \yii\helpers\Html, \some\other\vendor\Html or \my\custom\Html ?). And you have to declare it in every file because the alias “Html” can stand for different fully qualified classnames in different files and there’s no such thing as application-wide global “use” statement in PHP.
I get your point. But still, this doesnt change that it looks "ugly" for me to use such namespace includings in a view directly. if i started to use the \yii\helpers\Html in all my views, then i decid to inherit from \yii\helpers\Html my own Html-Helper Class, this means, i need to change in all my views the path…
Hi, yes your right. I dont have a problem to "use" for namespacing usw. Thats fine for me if its in the Controllers, Models or other "locigal" or "business relevant" Codes.
My only problem is to use it in Views. Because symfony uses twig they dont have the same issue like in yii. It’s a concept decision and because yii uses as is default View-Renderer plain PHP. I know, Twige is an official extension, but feels for me more complicated to use with widgets and all the great helpers of Yii.