module component autoloading

Right now I have this line of code in like 8 places of my module:



It's not clean, and if I change the name of the module, I have to change every one of those lines to reflect that.

Is there a way to configure which directories of the module will autoload in a single place (preferably somewhere in my TexteditModule class)?  (or any workaround ideas?)

Also is it considered "wrong" to call module components (eg widgets) from outside of the module (eg when the browser request is to a controller from within the main application)?  I got hints earlier that this was not meant to be…

Note: neither of these lines worked within TesteditModule::init() to solve the problem, which I expected to:



Are you using the latest svn? If so, the import statement in module's init should work. You can use Yii::import($this->id . '.models.*') so that you do not hardcode the ID in import.

Oh, it does work, just not for the widget that is called externally, which I was testing it in.  But you can't do anything about that, unless you make the CWebModule child load automatically.  But idk if that would be a good idea or not…

To use a widget from a module, you need to call Yii::app()->getModule($id) to "activate" that module first.

Ok, I put Yii::app()->getModule('textedit'); in the widget's init() method, that seem ok?  This way I don't have to call it in every place I use the widget.  The id is hard-coded, but I don't see a way around that…

since your module Id may not be fixed, maybe it is better for the caller (in the app) to call this method (in controller, for example).