Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 333
Adam Stacey Avatar asked Aug 03 '11 11:08

Adam Stacey


2 Answers

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

like image 77
richsage Avatar answered Oct 19 '22 13:10

richsage


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

like image 23
Hubert Perron Avatar answered Oct 19 '22 12:10

Hubert Perron