Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a module have its own config file?

Tags:

yii

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

like image 723
Hilmi Avatar asked Oct 07 '22 16:10

Hilmi


2 Answers

It does, already. in the CWebModule through $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.*',
            ));
        }
} ?>
like image 152
Hamad Avatar answered Oct 13 '22 05:10

Hamad


The way to do it is to make an array item for your module/etc in the params item of the main config array.

Look at 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 merge it with the main config array in the config 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
);

If you put your custom config array as the 2nd argument it will also overwrite attributes from the main config.

like image 24
Gung Foo Avatar answered Oct 13 '22 04:10

Gung Foo