Hi Guys,
How do you handle default Module / Extension configurations?
And what is the best way to do that?
Lets say you have for example a module.
You want to have a "default" configuration for the module…
but you also want to be able to "override" the default configuration in the main app config.
So you create a config file for your module:
app/modules/myModule/config/config.php
class Module extends \yii\base\Module
{
public $controllerNamespace = 'app\modules\myModule\controllers';
public function init()
{
parent::init();
\Yii::configure($this, require(__DIR__ . '/config/config.php'));
}
}
In myModule/config/config.php you have:
return [
'params' => [
'test' => 'module config default test param',
],
];
That should be the "default" param…
But now you want to override that param in app/config/web.php when you initialize the module.
For example like:
'modules' => [
'myModule' => [
'class' => 'app\modules\myModule\Module',
'params' => [
'test' => 'overwritten test param',
]
],
]
How would you handle that?
Suggestions / Opinions?
Or is it bad practise to do something like that when a module has his own configuration file?
Regards