Module : install and dynamic load


my webapp should be able to integrates modules, and theses modules should be installed through a simple procedure that would not imply to modify directly the app configuration file (I'm currently working on that).

Assuming a module has been correctly installed, a row is added in the module table.

Now, the question is : how is it possible to load a module and make it available to the webapp, without modifying the config file ? … in other words, how to dinamically load modules ?

My first idea is to extend CWebApplication and call setModules() on init() … or somewhere else. Maybe an event handler attached to the CWebApplication would be more clean ? … really, I don’t know, and hopefully someone will be able to help.



(ok ok I reply to my own post ;D)

So, this is what I did to dynamically load modules … is it ok ? … but please, if anyone has a better approach, let me know.

This is the webapp entry script (webapp/index.php):


// remove the following line when in production mode

defined('YII_DEBUG') or define('YII_DEBUG',true);


class ExtendedWebApplication extends CWebApplication {

	public function __construct($config=null)





	private function _loadModules()


		$criteria=new CDbCriteria;

		$criteria->select='id, name';


		$criteria->params=array(':enabled' => 1);


		if( count($modules)!=0)






$exWebApp=new ExtendedWebApplication($config);



(and it works fine)


Another way is modifying your config file like this:






in modules php do something like this:

return searchForModules();

function searchForModules(){

$arr = array();

/* add your modules dynamically here */

return $arr;


Or just add a funcition befor

hi sebas,

thanks for your answer … and good idea.

Acutally I think it also possible to overload CWebApplication:: beforeControllerAction() and load modules here. I didn’t try that (just read it in the api doc) but maybe that’s better than overloading the contructor… I don’t know what a best-practise would be … Yii provides sooo many ways to reach the same goal ;)

[edit] … no, forget it ! when beforeControllerAction is called, the controller is already loaded … too late to load modules !