C
C
Crash2017-06-12 11:17:47
Yii
Crash, 2017-06-12 11:17:47

How to make different configs for the database in Yii2 advanced without extra crutches?

Hello! At the request of the customer, I started a project on Yii2 advanced. I would not have done this of my own free will, the basic template was always enough for my eyes. The question arose about separating the database configs for localhost and hosting. So far, I did it as in basic: in /common/config/main-local.php I wrapped the configs in the $config variable and added below:

if (YII_ENV_DEV){
    $config['components']['db'] = require(__DIR__ . '/db-local.php');
}

As I understand it, this is a crutch, in a good way you need to configure it through the environments (environments folder), but how to do it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-06-12
@Bandicoot

the environments folder contains a skeleton for environment dependent application settings. That is, in fact, when you deploy the project in a certain environment and execute the init command, the configs are copied from the environments folder to the corresponding folders and already in them you specify all the parameters that depend on the environment (access to the database, etc.). Accordingly, in the configs /common/config/main.php, etc. settings not related to the environment are indicated (list of components, etc.)
in total you need to:
1. Initialize the project using init
2. Fill in the access data in the configs with the -local prefix

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question