How to create a custom yaml config file in Symfony

Guillaume Flandre picture Guillaume Flandre · Mar 30, 2010 · Viewed 13.2k times · Source

What I want to do is quite simple: store data in a custom config file that I want to read later on.

I created my file something.yml that I put in the global config directory. It looks like that:

prod:
  test:  ok

dev:
  test: ko

all:
  foo:  bar
  john: doe

Then I copied the config_handlers.yml and also put it in the config directory and added the following at the top of the file:

config/something.yml:
  class:    sfDefineEnvironmentConfigHandler
  param:
    prefix: something_

But if I'm calling sfConfig::get("something_foo"); I keep getting NULL.

What did I do wrong? I just want to read values, so no need to create a custome config handler, right?

I've read the doc here: http://www.symfony-project.org/book/1_2/19-Mastering-Symfony-s-Configuration-Files even though I'm running 1.4 (I don't think that changed since then).

Edit: Of course I can use sfYaml::load() but I'd like to do things in a better way.

Answer

Syam picture Syam · Dec 16, 2010

Do not modify the index.php this is dirty!

Juste add this line to your app/frontend/config/frontendConfiguration.class.php

require_once($this->getConfigCache()->checkConfig('config/something.yml'));

(adapt with your own app name)