Created
October 9, 2017 21:55
-
-
Save VictorFursa/cae3e38dde7f415be6e71a4aab740d54 to your computer and use it in GitHub Desktop.
позднее статическое связывание
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\modules\admin\models; | |
use yii\db\ActiveRecord; | |
class Active extends ActiveRecord | |
{ | |
public static function getDb() | |
{ | |
return \Yii::$app->db2; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** app/config */ | |
return [ | |
'class' => 'yii\db\Connection', | |
'dsn' => 'mysql:host=localhost;dbname=active', | |
'username' => 'root', | |
'password' => 'password', | |
'charset' => 'utf8', | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** MODEL TYPE */ | |
namespace app\modules\admin\models; | |
class Type extends Active | |
{ | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\modules\admin\controllers; | |
use app\modules\admin\models\Type; | |
public function actionCreate() | |
{ | |
$model = new Type(); | |
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
return $this->redirect(['view', 'id' => $model->id]); | |
} | |
return $this->render('create', [ | |
'model' => $model, | |
]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** app/web */ | |
$db = require __DIR__ . '/db.php'; | |
$db2 = require __DIR__ . '/db2.php'; | |
'components' => [ | |
'db' => $db, | |
'db2' => $db2, | |
]; | |
... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment