Handling Multiple Config Files in symfony and non symfony

帅比萌擦擦* 提交于 2020-01-05 03:37:26

问题


In my web application some of my application is in symfony and some is in non symfony.

As a result there are multiple database connection files (say database connections files one of which is a yml file and other is a php file.)

I am thinking to create a table and store database connection in this table and then create config files from them.

Is there any other approach for this.


回答1:


You should keep the databases.yml and load it from your non symfony application.

Inside your non symfony application, you can use the Yaml component from Symfony 2:

use Symfony\Component\Yaml\Parser;

$yaml     = new Parser();
$database = $yaml->parse(file_get_contents('/path/to/config/databases.yml'));

Or you can use sfYaml (copy/paste it insid your non-symfony project) and load the yml like this:

// if you don't use an autoload
require_once('/path/to/config/sfYaml.class.php');

$database = sfYaml::load('/path/to/config/databases.yml');


来源:https://stackoverflow.com/questions/15803028/handling-multiple-config-files-in-symfony-and-non-symfony

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!