Can a module have its own configuration file?

I just want to know if we can add a configuration file that extends main.conf in the module

+5
source share
3 answers

He is doing it already. in CWebModule via $ this-> setComponents as follows:

<?php

    class AccountModule extends CWebModule
    {
        public function init()
        {
            // this method is called when the module is being created
            // you may place code here to customize the module or the application

            $this->setComponents(array(
                'errorHandler' => array(
                        'errorAction' => 'module/default/error'),
                'defaultController' => 'default',
                'user' => array(
                        'class' => 'ModuleWebUser',
                        'allowAutoLogin'=>true,
                        'loginUrl' => Yii::app()->createUrl('module/default/login'),
                )
            ));

            // import the module-level models and components or any other components..
            $this->setImport(array(
                'module.models.*',
                'module.components.*',
            ));
        }
} ?>
+2
source

The way to do this is to make an array element for your / etc module in the params element of the main configuration array.

Check out this forum post: http://www.yiiframework.com/forum/index.php/topic/24617-custom-configuration/

If you want your configuration to be in a separate file, you can combine it with the main configuration array in the configuration file! something like this should work:

include("custom_config.php"); // define $array_from_custom_conf inside this file
return array_merge(
   array(/*main_config_array from main.php*/),
   $array_from_custom_conf
);

, .

+1

, :

  • wiki.
  • Regarding this "feature request", it is not a big surprise that this has already been requested on the Yii forums. See here and here .
+1
source

All Articles