Right now I have this line of code in like 8 places of my module:
<?php
Yii::import('textedit.models.*');
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…
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…
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…