Extend Yii

Is there a way to extend this class here ?


Or maybe there’s a workaround for this.

I don’t want to keep all the module declarations in “main.php”, I’d prefer to load them manually.

And extending “CWebApplication” partially solved the problem, if I access “…index.php?r=moduleName” it works just fine, but if there’s A


somewhere I’m getting an error. (obviously)

So what I’m trying to do is:

Don’t declare the modules in “protected/config/main.php” but load them only if they are required.

Has someone tried to make something similiar ?

Thank you for your time.

Have a nice day…

alternative solution if you store the module declarations in the different files and merge these in the main.php, e.g.:


return array(


    'modules'=> CMap::mergeArray(


        // require(dirname(__FILE__).'/modules/admin.php'),


        // require(dirname(__FILE__).'/modules/b.php'),










here the "admin" and "b" module is not loaded.

#Argent - this will only separate the configurations, but I’m more concerned about performance.

I don’t want all modules to be loaded whyle I actually need only one module, and I can’t think of a way to achieve this without hacking/modifying the Yii_core.

Any ideas are highly appreciated

If you declare all your modules in your config/main.php there is no performance problem.

The modules will not be loaded at startup.

A module is only loaded and initialized when


is called, means on the first call.

But don’t use the modules alias elsewhere in the config/main.php or in a Yii::import statement.

For example:








If necessary to inlcude parts of a module (components, controllers…) in the config/main.php, you can use ‘application.modules.mymodule…’ instead to avoid creating the module on application init.

Analogous: Avoid to use


because this line, will lead to initialize the module.