Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add an array with values in Symfony2 configuration?

Tags:

php

yaml

symfony

I would like to add a simple list of values in a configuration files (config.yml). For example :

my_bundle:
    columns: ["col1", "col2"]

When adding the node to the configuration parser, it simply fails :

$rootNode = $treeBuilder->root('my_bundle');
$rootNode->arrayNode('columns')->children()->end();

Here is the error :

InvalidConfigurationException: Unrecognized options "0, 1" under "my_bundle.columns"

What am I missing? Is this even possible?

like image 679
i.am.michiel Avatar asked Aug 05 '13 07:08

i.am.michiel


1 Answers

If you want to achieve a node like this, just do:

$rootNode
    ->children()
        ->arrayNode('columns')
            ->prototype('scalar')
            ->end()
        ->end()
    ->end()
;
like image 90
Touki Avatar answered Oct 12 '22 03:10

Touki