Using the configuration class, how do I define an array node without numeric keys? The children of the array do not represent further configuration options. Rather, they will be a list that will not be able to be overwritten selectively, only as a whole.
So far I have:
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder;
$root = $treeBuilder->root('acme_base');
$root
->children()
->arrayNode('entities')
// Unfortunately, this doesn't work
->defaultValue(array(
'Acme\BaseBundle\Entity\DefaultEntity1',
'Acme\BaseBundle\Entity\DefaultEntity2',
))
->end()
->end();
return $treeBuilder;
}
In app/config.yml
, I want to be able to overwrite it like this:
acme_base:
entities:
- 'Acme\BaseBundle\Entity\AnotherEntity1'
- 'Acme\BaseBundle\Entity\AnotherEntity2'
- 'Acme\BaseBundle\Entity\AnotherEntity3'
- 'Acme\BaseBundle\Entity\AnotherEntity4'
I think you need
$root
->children()
->arrayNode('entities')
->addDefaultsIfNotSet()
->prototype('scalar')->end()
->defaultValue(array(
'Acme\BaseBundle\Entity\DefaultEntity1',
'Acme\BaseBundle\Entity\DefaultEntity2',
))
->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