Does it hurt to have a lot of auto import directories?

Does it hurt to have a lot of auto import directories as defined in the 'import' configuration?  Will this slow the app down?  I feel like it might, but I would like some advice.

Because I have some controllers set to auto-import on demand (because I have some other controllers that inherit from the auto-load controllers), I am wondering if it is better just to import() them

I don't know because I haven't try to auto import with many component. But I think it will not effect all application performance. Just will effect on event importing component or a class because Yii use a lazy loading method to load resource just when it will use. Yii will not load all component even if you auto load many component on your configuration.

Correct me if I'm wrong…

Do not import too many directories because it relies on PHP include_path. If you have a long PHP include_path, the performance may be degraded when including a file without absolute path.

Importing classes should be fine.

Ok.  BTW, and idea just struck me.

I see you can make path aliases with YiiBase::setPathOfAlias(), but wouldn't it be nice to set path aliases in your config file?  For instance right now I have this in the config:



	'import'=>array(


		'application.models.*',


		'application.components.*',


		'application.components.helpers.*',


		'application.components.behaviors.*',


		'application.components.widgets.*',


		'application.extensions.*',


	),


The reason having these set to auto import is because it gets tiresome typing out paths when using a widget for example.

What if you could define aliases like this:



	'aliases'=>array(


		'models'=>'application.models',


		'components'=>'application.components',


		'helpers'=>'application.components.helpers',


		'behaviors'=>'application.components.behaviors',


		'widgets'=>'application.components.widgets',


		'extensions'=>'application.extensions',


	),


Now I don't have the negative effects of a long include_path, and I can call a widget like this:

<?php $this->widget('widgets.MyWidget'); ?>

Good idea, but it also introduces new usage that needs to be educated. Also, it is mainly helpful for using widgets, not other classes.

You could achieve the similar effect by inserting the following code in app config:



<?php


Yii::setPathOfAlias('models', Yii::getPathOfAlias('application.models'));


Not as pretty as your approach though, but less magic.

Yes, it could be useful for widgets, but also:

CClientScript::register<something>File()

For instance:

CClientScript::registerCssFile('Css.MyFile.css')

Then if you want to move all your css files to another directory, you can just change your configured alias and not go through all your code.

And also the view rendering functions.

I just posted issue #286 (http://code.google.c…s/detail?id=286) which may help with this. Code is attached to page.

Quote

Ok.  BTW, and idea just struck me.

I see you can make path aliases with YiiBase::setPathOfAlias(), but wouldn't it be nice to set path aliases in your config file?  For instance right now I have this in the config:



	'import'=>array(


		'application.models.*',


		'application.components.*',


		'application.components.helpers.*',


		'application.components.behaviors.*',


		'application.components.widgets.*',


		'application.extensions.*',


	),


The reason having these set to auto import is because it gets tiresome typing out paths when using a widget for example.

What if you could define aliases like this:



	'aliases'=>array(


		'models'=>'application.models',


		'components'=>'application.components',


		'helpers'=>'application.components.helpers',


		'behaviors'=>'application.components.behaviors',


		'widgets'=>'application.components.widgets',


		'extensions'=>'application.extensions',


	),


Now I don't have the negative effects of a long include_path, and I can call a widget like this:

<?php $this->widget('widgets.MyWidget'); ?>

Jonah, I just had a thought. Your approach, as Qiang said, would require syntax dissemination and be a fundamental shift in the way aliases are utilized in Yii.

I don't think that's a good thing.

However… a NEW section within the config file. This would be a decent approach as only people who need it can use it, it is a new feature, and can easily be implemented.

For example, we can add a new section called 'importAliases'. In this array are your mappings. Next, add a method to YiiBase(::importAliases) which will read the array and do the mappings.

Just a thought…