简体   繁体   English

加载不同的数据库Symfony2

[英]Load different Database Symfony2

How can I load different database for production and development environment ? 如何为生产和开发环境加载不同的数据库?

In parameters.yml I have the main database configuration, but I don't know how to add the dev database with differets parameters. 在parameters.yml中,我具有主要的数据库配置,但是我不知道如何添加具有差异参数的dev数据库。

I'm looking for this on Google but I can't find any help. 我正在Google上寻找它,但找不到任何帮助。

Maybe with config_dev.yml and config_prod.yml? 也许使用config_dev.yml和config_prod.yml? but I'm not sure how to do that. 但我不确定该怎么做。

Any help would be appreciated. 任何帮助,将不胜感激。 Thanks. 谢谢。

I will do something like this: 我会做这样的事情:

Files hierarchy: 1) parameters.yml - for common parameters 2) create parameters_dev.yml - only dev db connection params 3) create parameters_prod.yml - only prod db connection params 文件层次结构:1) parameters.yml用于通用参数2)创建parameters_dev.yml仅开发数据库连接参数3)创建parameters_prod.yml仅产品db连接参数

In head of config files: 1) config.yml 在配置文件的开头:1) config.yml

imports:
    - { resource: parameters.yml }

2) config_dev.yml 2) config_dev.yml

imports:
    - { resource: config.yml }
    - { resource: parameters_dev.yml }

3) config_prod.yml 3) config_prod.yml

imports:
    - { resource: config.yml }
    - { resource: parameters_prod.yml}

You can use Parameters to store environment-specific (or system-specific) variables easily. 您可以使用参数轻松存储特定于环境的(或特定于系统的)变量。

For example, in a config/parameters.yml : 例如,在config/parameters.yml

parameters:
    parameter_name: some_value

In config.yml , at the top: config.yml ,在顶部:

imports:
    - { resource: parameters.yml }

Then, you can substitute a parameter using the syntax "%parameter_name%" where the variable's value should appear. 然后,您可以使用语法"%parameter_name%"替换参数,变量的值应出现在该位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM