How do you load config settings from the database in Symfony2?

僤鯓⒐⒋嵵緔 提交于 2019-12-03 02:51:35

问题


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.

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

Cheers

Adam


回答1:


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 }

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).




回答2:


Take a look at the UnifikDatabaseConfigBundle. It creates a database structure that enable configuration of Symfony parameters straight from the database.



来源:https://stackoverflow.com/questions/6925581/how-do-you-load-config-settings-from-the-database-in-symfony2

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