Configuration in Symfony is equal to valdiating the configuration.
I want to validate my configuration with the treebuilder. In the yml-example, i give a quite example of how the config-tree will look like (in future, the tree will be even bigger than now). But to do this, i need a to create a structure.
Now Could you help me, to create the treebuilder? I've tried everything with arrayNode and prototypes, but it won't work. I get exceptions like
"FatalErrorException: Error: Call to undefined method Symfony\Component\Config\Definition\Builder\NodeBuilder::prototype() in /var/www/menu_bundle/src/my/MenuBundle/DependencyInjection/Configuration.php line 29 "
Base idea:
I want to generate a Symfony2-bundle, which creates a menuStructure in HTML. For generateing the HTML-Code, i need to pull the yaml-configuration in to an object-structure, this works, but the validating with symfony doesn't work...
Here is a quick example on how the menu.yml should look like:
my_menu_structure:
menu:
name: test
cssClass: blubb
children:
child:
name: item1
route: route1
position: 0
child:
name: item11
route: route11
position: 0
child:
name: item2
route: route2
position: 1
Now i want to configure the Treebuilder in Symfony2, but it won't work..
After a few times of trying, this is my last version:
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('my_menu');
$rootNode
->children()
->arrayNode('menu')
->scalarNode('cssClass')
->defaultValue(array())
->prototype('array')
->scalarNode('name')
->scalarNode('route')
->scalarNode('Position')
->prototype('array')
->end()
->end()
->end();
I have build the objects for Menu and MenuItems. Everything works so far, but i can't configure the treebuilder. What I'm searching for, is a way to reuse a part (menuItem-: name, route and children) in the treebuilder, but everything I found so far, couldn't help me... Everything else works, my only problem is, that I can't configure the Treebuilder and I can't get the config out of the yml with $this->container->get('menu.name'). This throws an exception: You have requested a non-existent service "menu.name".
So far, I've tried some Configuration with prototype('array'), but phpStorm says everytime, it can't find a scalarNode as a child of prototype or of ->prototype()->children()->scalarNode()..