views:

851

answers:

3

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.

+2  A: 

It's really easy, but also a little bit hacky:

Create the file /config/config_handlers.yml and add this:

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

Then add these two lines to /web/index.php after ... getApplicationConfiguration() (and also add them to frontend_dev.php and wherever you want this config file to be available):

$configCache = new sfConfigCache($configuration);
include($configCache->checkConfig('config/something.yml'));

So your /web/index.php might look like this afterwards:

<?php
require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');

$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false);
$configCache = new sfConfigCache($configuration);
$configCache->checkConfig('config/something.yml');
sfContext::createInstance($configuration)->dispatch();

Btw: This is also in the documentation you cited, although the checkConfig() call is in a different place. Look for this: "When you need the code based on the map.yml file and generated by the myMapConfigHandler handler in your application, call the following line:"

Have fun ;-)

naag
Thanks, but when I do this, I get the error:
Prasad
A: 

Have you cleared your cache files?

php symfony cc

In prodution environment all config files, classes, etc... are being cached.

Martin Sikora
A: 

I have the same problem and I'm using symfony version 1.29 . And the cache file for something.yml is empty!

cache/frontend/dev/config/config_something.yml.php

The suggested:

include($configCache->checkConfig('config/something.yml'));

doesn't work.

Anyone found an answer?

antitoxic