Symfony YML Files - Can You Get Associative Arrays More Than 1 Level?

I have a data download that I want to save to /apps/frontend/modules/builder/config/module.yml.

It looks something like this for me:

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

In the actions.class file, if I write this:

sfConfig::get('mod_builder_series_options_compact');

I get it

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

Perfect. But I want to write this:

sfConfig::get('mod_builder_series_options');

What gives NULL.

Is there a way to get this to return the full associative array to full depth so that I can iterate through various parameters?

+3
source share
2 answers

You can add a level with a dot before its name to force the array at a specific level:

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

You should now have access to your settings with:

sfConfig::get('mod_builder_series_options');

, .

+5

, , ...

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

:

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

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

    )

)

, sfConfig , sfYaml, , , !

, - !

+1

Source: https://habr.com/ru/post/1764939/


All Articles