MatMouth
MatMouth

Reputation: 943

Symfony2 Bundle configuration

I am trying to use a custom configuration for my bundle

#app/config.yml
config.yml
        my_app:
                level1:
                    level2:
                        - "first data"
                        - "second data"

How can I get those information a controller or a service

#My/AppBundle/DependencyInjection/Configuration.php
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('my_app');

        $rootNode
            ->children()
                ->arrayNode('level1')
                    ->children()
                        ->arrayNode('level2')->end()
                    ->end()
                ->end()
            ->end()
    ;

This code generate the following error:

InvalidConfigurationException in ArrayNode.php line 317: Unrecognized options "0, 1" under "my_app.level1.level2"

How can do that please ?

Upvotes: 0

Views: 96

Answers (1)

Anthony Matignon
Anthony Matignon

Reputation: 76

I think you should do something like :

->children()
    ->arrayNode('level2')
        ->prototype('scalar')->end()
    ->end()

If you need more helps, check here for more information

Upvotes: 2

Related Questions