waaadim
(Vrihlea)
December 24, 2013, 4:30pm
1
Is there a way to extend this class here ?
http://www.yiiframework.com/doc/api/1.1/CModule/#getModule-detail
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
Yii::app()->getModule("moduleName")
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…
argent
(Argent Hun)
December 24, 2013, 8:52pm
2
alternative solution if you store the module declarations in the different files and merge these in the main.php, e.g.:
#config/main.php
return array(
......
'modules'=> CMap::mergeArray(
require(dirname(__FILE__).'/modules/development.php'),
// require(dirname(__FILE__).'/modules/admin.php'),
require(dirname(__FILE__).'/modules/a.php'),
// require(dirname(__FILE__).'/modules/b.php'),
array(
'something'=>array(
......
),
......
)
),
......
);
here the "admin" and "b" module is not loaded.
waaadim
(Vrihlea)
December 25, 2013, 8:30am
3
#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
joblo
(Joe)
December 25, 2013, 11:07am
4
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
Yii::app()->getModule("mymodule")
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:
'components'=>array(
..
'acomponent'=>'mymodule.components.XY',
..
)
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
Yii::import('mymodule.components.*')
because this line, will lead to initialize the module.
Use
Yii::import('application.modules.mymodule.components.*')
instead.