I'm building a application where I give the admin the option to activate/deactivate modules using the web administration so he doesn't have to edit the configuration files manually so I need to know what modules are inside the module/ folder. I could parse the folder and see what's inside but it may be a better solution.
Something like Yii::app ()->getModules () but with a result which includes the loaded/unloaded modules. Is there such a method I can use?
Page 1 of 1
Retrieve all modules
#2
Posted 17 December 2009 - 06:26 AM
Did you try that? I think that exact method should be available: http://www.yiiframew...tModules-detail (CApplication extends CModule).
#3
Posted 17 December 2009 - 06:28 AM
Yii::app ()->getModules () only returns the modules which are manually added in the config file:
But this is not very friendly for noobs so I need a way to know exactly all the modules available in the modules/ dir...loaded or not.
'modules'=>array('forum',...)But this is not very friendly for noobs so I need a way to know exactly all the modules available in the modules/ dir...loaded or not.
#4
Posted 17 December 2009 - 07:29 AM
manilodisan, on 17 December 2009 - 06:11 AM, said:
I'm building a application where I give the admin the option to activate/deactivate modules using the web administration so he doesn't have to edit the configuration files manually so I need to know what modules are inside the module/ folder. I could parse the folder and see what's inside but it may be a better solution.
Something like Yii::app ()->getModules () but with a result which includes the loaded/unloaded modules. Is there such a method I can use?
Something like Yii::app ()->getModules () but with a result which includes the loaded/unloaded modules. Is there such a method I can use?
try this:
/**
* Find a module searching in application modules and if it's not found there
* looks in modules' modules
* @param String $moduleID The model to find
* @return The module, if it's found else null
*/
public static function findModule($moduleID) {
if(Yii::app()->getModule($moduleID)) {
return Yii::app()->getModule($moduleID);
}
$modules = Yii::app()->getModules();
foreach ($modules as $mod=>$conf) {
if(Yii::app()->getModule($mod)) {
return self::findInModule(Yii::app()->getModule($mod), $moduleID);
}
}
return null;
}
/**
* Search for a child module
* @param String $parent The parent module
* @param String $moduleID The module to find
* @return The module, if it's not found returns null
*/
private static function findInModule($parent, $moduleID) {
if ($parent->getModule($moduleID)) {
return $parent->getModule($moduleID);
} else {
$modules = $parent->getModules();
foreach ($modules as $mod => $conf) {
return $this->findInModule($parent->getModule($mod), $moduleID);
}
}
return null;
}
#5
Posted 17 December 2009 - 07:35 AM
This is a findModule function. I need something that returns all the available modules not a find function.
Share this topic:
Page 1 of 1

Help












