Handling Multiple Config Files in symfony and non

2019-07-23 17:30发布

问题:

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');