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?
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With