Skip to content

Commit 4b06f2b

Browse files
committed
Allow configuration of different database connection for all models
Close #918
1 parent e98024c commit 4b06f2b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Module.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class Module extends BaseModule
9797
*/
9898
public $debug = false;
9999

100+
/** @var string The database connection to use for models in this module. */
101+
public $dbConnection = 'db';
102+
100103
/** @var array The rules to be used in URL management. */
101104
public $urlRules = [
102105
'<id:\d+>' => 'profile/show',
@@ -107,4 +110,12 @@ class Module extends BaseModule
107110
'recover/<id:\d+>/<code:[A-Za-z0-9_-]+>' => 'recovery/reset',
108111
'settings/<action:\w+>' => 'settings/<action>'
109112
];
113+
114+
/**
115+
* @return string
116+
*/
117+
public function getDb()
118+
{
119+
return \Yii::$app->get($this->dbConnection);
120+
}
110121
}

traits/ModuleTrait.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22

3-
43
namespace dektrium\user\traits;
54

65
use dektrium\user\Module;
76

87
/**
98
* Trait ModuleTrait
9+
*
1010
* @property-read Module $module
1111
* @package dektrium\user\traits
1212
*/
@@ -19,4 +19,12 @@ public function getModule()
1919
{
2020
return \Yii::$app->getModule('user');
2121
}
22+
23+
/**
24+
* @return string
25+
*/
26+
public static function getDb()
27+
{
28+
return \Yii::$app->getModule('user')->getDb();
29+
}
2230
}

0 commit comments

Comments
 (0)