Selaa lähdekoodia

Merge pull request #1761 from lucianobaraglia/master

Basic app: DB configuration in separated file
Carsten Brandt 12 vuotta sitten
vanhempi
commit
d35698afe6
3 muutettua tiedostoa jossa 14 lisäystä ja 14 poistoa
  1. 3 7
      config/console.php
  2. 9 0
      config/db.php
  3. 2 7
      config/web.php

+ 3 - 7
config/console.php

@@ -3,6 +3,8 @@
 Yii::setAlias('@tests', dirname(__DIR__) . '/tests');
 
 $params = require(__DIR__ . '/params.php');
+$db = require(__DIR__ . '/db.php');
+
 return [
 	'id' => 'basic-console',
 	'basePath' => dirname(__DIR__),
@@ -22,13 +24,7 @@ return [
 				],
 			],
 		],
-		'db' => [
-			'class' => 'yii\db\Connection',
-			'dsn' => 'mysql:host=localhost;dbname=yii2basic',
-			'username' => 'root',
-			'password' => '',
-			'charset' => 'utf8',
-		],
+		'db' => $db,
 		'fixture' => [
 			'class' => 'yii\test\DbFixtureManager',
 			'basePath' => '@tests/unit/fixtures',

+ 9 - 0
config/db.php

@@ -0,0 +1,9 @@
+<?php
+
+return [
+	'class' => 'yii\db\Connection',
+	'dsn' => 'mysql:host=localhost;dbname=yii2basic',
+	'username' => 'root',
+	'password' => '',
+	'charset' => 'utf8',
+];

+ 2 - 7
config/web.php

@@ -1,6 +1,7 @@
 <?php
 
 $params = require(__DIR__ . '/params.php');
+$db = require(__DIR__ . '/db.php');
 
 $config = [
 	'id' => 'basic',
@@ -29,13 +30,7 @@ $config = [
 				],
 			],
 		],
-		'db' => [
-			'class' => 'yii\db\Connection',
-			'dsn' => 'mysql:host=localhost;dbname=yii2basic',
-			'username' => 'root',
-			'password' => '',
-			'charset' => 'utf8',
-		],
+		'db' => $db,
 	],
 	'params' => $params,
 ];