3

I have this config in config.yml file in my Symfony 3.5 project:

my_config:
    token: mHSHlSHl-QqSHlX-SHlQqShzO2ibzGnsNk-Q
    username: test

    development:
        developers_id: [130]
        maintenance:
            enable: true
            text: "text of text"

I have a bundle to parse this config in my configuration.php file. In the bundle dependency injection I have this code:

$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('my_bundle');
$rootNode->children()
    ->scalarNode("username")
    ->end()
    ->scalarNode("token")
        ->isRequired()
    ->end()
    ->arrayNode('development')
        ->children()
            ->booleanNode('send_log')
                ->defaultFalse()
            ->end()
            ->arrayNode('developers_id')
                ->prototype('scalar')
            ->end()
            ->arrayNode('maintenance')
                ->children()
                    ->booleanNode('enable')
                        ->defaultFalse()
                    ->end()
                    ->scalarNode('text')
                        ->defaultValue('default text')
                    ->end()
                ->end()
            ->end()
        ->end()
    ->end()
->end();

return $treeBuilder;

When I run this code I get this error:

Attempted to call an undefined method named "arrayNode" of class "Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition".

What should I do?

3
  • Try clearing your cache (cache:clear [--env=...] [--no-debug]), if that doesn't help: Break up the code right before the line that throws the error and dump $rootNode at that point to see it's type. Commented Oct 22, 2017 at 23:55
  • @ccKep I can't run commands because i get error Commented Oct 23, 2017 at 18:13
  • you ran just remove cache with rm -rf var/cache Commented Jul 27, 2018 at 9:58

1 Answer 1

2

I get this error because after ->prototype('scalar') I didn't write ->end(), I added ->end() and my problem was solved.

the right syntax is like this:

->arrayNode('developers_id')    
    ->prototype('scalar')
    ->end()
->end()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.