如何从Symfony2中的数据库加载配置设置? [英] How do you load config settings from the database in Symfony2?

查看:58
本文介绍了如何从Symfony2中的数据库加载配置设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在config.yml文件中有许多设置.

I have a number of settings that are currently in the config.yml file.

展望未来,我希望能够开发一个界面,以便管理员可以更新这些设置,因此我希望能够通过数据库管理这些设置.

Going forward I want to be able to develop an interface where administrators will be able to update these settings, so I want to be able to manage these settings through the database.

我如何将这些设置从数据库加载到Symfony2中,以及何时何地加载它们?

How would I be able to load these settings from the database into Symfony2 and where and when would I load them?

欢呼

亚当

推荐答案

有一个食谱文章,简要介绍了如何执行此操作(尽管很简短),并参考了从Drupal外部加载设置.基本思想是在您的配置中执行类似的操作(例如yml):

There's a cookbook article that explains roughly how to do this (albeit briefly), in reference to loading in settings externally from Drupal. The basic idea is to do something like this in your config (example is yml):

# app/config/config.yml
imports:
    - { resource: parameters.php }

然后在parameters.php中,您可以执行所需的任何操作来获取配置,并按如下所示进行设置:

then in parameters.php you can do whatever you need to to get your config, and set it as follows:

$container->setParameter('my.db.parameter', $value);

(摘自食谱,稍作修改).

(taken from the cookbook, slightly modified).

这篇关于如何从Symfony2中的数据库加载配置设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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