在 symfony 和非 symfony 中处理多个配置文件 [英] Handling Multiple Config Files in symfony and non symfony

查看:15
本文介绍了在 symfony 和非 symfony 中处理多个配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网络应用程序中我的一些应用程序在 symfony 中,有些在非 symfony 中.

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

因此有多个数据库连接文件(比如数据库连接文件,其中一个是 yml 文件,另一个是 php 文件.)

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.

推荐答案

你应该保留 databases.yml 并从你的非 symfony 应用程序加载它.

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

在您的非 symfony 应用程序中,您可以使用 来自 Symfony 2 的 Yaml 组件:

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

或者你可以使用 sfYaml (将其复制/粘贴到您的非 symfony 项目中)并像这样加载 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');

这篇关于在 symfony 和非 symfony 中处理多个配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆