With the Symfony2 TreeBuilder, its possible to configure prototypes for each node inside an array node, e.g. to support a configuration like
foo:
xxx: { foo: bar}
yyy: { foo: bar}
Where there are any number of xxx, yyy and so on (any value at all) nodes using a structure like
$rootNode
->arrayNode('foo')
->prototype('array')
->children()
->scalarNode('foo')
I would like to create another level of the same thing without introducing another named node in between, e.g. to support a configuration like
foo:
xxx:
aaa: { foo: bar}
bbb: { foo: bar}
yyy:
ccc: { foo: bar}
ddd: { foo: bar}
where there can be any number of xxx, yyy and so on nodes, each of which can contain any number of other aaa, bbb etc. nodes.
Is there any way to achieve this? Calling ->prototype()
directly under the ->children()
of another prototype call doesn't work, as the prototypes don't seem to support nested prototypes. As a result I'm having to hard code specific values for the xxx and yyy, limiting the flexibility of the bundle I'm writing.
Checked in symfony 2.2, nesting works.
Don't use ->children()
between nested ->prototype()
:
$rootNode->children()
->arrayNode('foo')
->prototype('array')
->prototype('array')
->children()
->scalarNode('foo');
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