views:

37

answers:

2

Hi,

I have a load of data I want to store here: /apps/frontend/modules/builder/config/module.yml

I have it looking something like:

all:
  series_options:
    compact:
      name: Compact
      description: Something small.
      enabled: 1
    large:
      name: Large
      description: Bit bigger.
      enabled: 0

In the actions.class if I write this:

sfConfig::get('mod_builder_series_options_compact');

I get this

Array
(
  [name] => Compact
  [description] => Something small.
  [enabled] => 1
)

Perfect. But I want to write this:

sfConfig::get('mod_builder_series_options');

Which gives NULL.

Is there any way I can get this to return the full associative array to its full depth so I can iterate through the different options?? It seems I can only get it to go down one level...

Thanks, Tom

A: 

Typical, as soon as I resort to posting the answer hits me in the face...

$series = sfYaml::load('../apps/frontend/modules/builder/config/module.yml');  
print_r($series);die;

Returns:

Array
(
  [all] => Array
    (
        [series_options] => Array
            (
                [compact] => Array
                    (
                        [name] => Compact
                        [description] => Something small.
                        [enabled] => 1
                    )

                [large] => Array
                    (
                        [name] => Large
                        [description] => Bit bigger.
                        [enabled] => 0
                    )
            )

    )

)

Guessing that sfConfig wasnt really meant for this purpose, where sfYaml certainly looks like it was!

Hope this helps someone else!

Tom
A: 

You can add a level with a dot before its name to force array on certain level:

all:
  .options:
    series_options:
      compact:
        name: Compact
        description: Something small.
        enabled: 1
      large:
        name: Large
        description: Bit bigger.
        enabled: 0

Now you should be able to access your settings with:

sfConfig::get('mod_builder_series_options');

Remember that module configuration is only accessible in the module it is defined.

kuba