-
-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to configure a module with a config file #169
Comments
i cant figure out if its a bug or something else. i configure module exactly as above mentioned by @samdark . somehow config file is ignored for example mailer component viewPath is ignored i cant overide //module config file
return [
'params' => [],
'components' => [
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => true,
'viewPath' => '@app/modules/user/mail'
],
],
];
|
Is it right to write in the config's module some child modules or i can to use only "modules" property (https://www.yiiframework.com/doc/guide/2.0/en/structure-modules#nested-modules)? Something like this (config in the module's directory):
|
I don't think sub-modules are a good idea. |
I transfer from yii 1 and there uses nested modules by importing and i need to keep the structure. |
No idea. Try it. |
Maybe better is: use yii\helpers\ArrayHelper;
class Module extends \yii\base\Module
{
public function __construct($id, $parent = null, $config = [])
{
$config = ArrayHelper::merge(
require __DIR__ . '/config.php',
$config
);
parent::__construct($id, $parent, $config);
} In this case you can override defaults in app's config(e.g. common/config/main-local.php for advanced template) |
In projects use follow base module: <?php
namespace d3system\yii2\base;
use yii\base\Module;
class D3Module extends Module
{
public $configFilePath;
/**
* @var array panels for PanelWidgets
*/
public $panels;
public function __construct($id, $parent = null, $config = [])
{
if(isset($config['configFilePath'])){
$config = array_merge($config,include $config['configFilePath']);
}
parent::__construct($id, $parent, $config);
}
} in config file by setting define, where is module config file: 'modules' => [
'wiki'=>[
'class'=>'asinfotrack\yii2\wiki\Module',
'configFilePath' => __DIR__ . '/module_wiki.php',
],
] |
config.php:
The text was updated successfully, but these errors were encountered: