June 17, 2015

June 17, 2015
In this article, we are going to discuss about How to load the modules dynamically from DB or from Directory in YII framework. In Yii application development, we can set up modules configuration in config.php.  Sometimes, we need to load modules configuration from database or directory glob. After searching the topic in google and comparing some solutions, I found the elegant way to implement this. Hope it can help.

You can modify the index.php file of your Yii application.


class ExtendableWebApp extends CWebApplication {
        protected function init() {
                // this example dynamically loads every module which can be found
                // under `modules` directory
                // this can be easily done to load modules
                // based on MySQL db or any other as well
                foreach (glob(dirname(__FILE__).'/protected/modules/*', GLOB_ONLYDIR) as $moduleDirectory) {
                return parent::init();

$app=new ExtendableWebApp($config);

Reference: http://www.yiiframework.com/forum/index.php/topic/23467-dynamically-load-modules-models-and-configurations/page__p__144316#entry144316


Post a Comment