mat*_*ndr 7 configuration symfony
使用配置类,如何在没有数字键的情况下定义数组节点?数组的子代不代表进一步的配置选项.相反,它们将是一个无法有选择地覆盖的列表,仅作为一个整体.
到目前为止,我有:
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;
}
Run Code Online (Sandbox Code Playgroud)
在app/config.yml,我希望能够像这样覆盖它:
acme_base:
entities:
- 'Acme\BaseBundle\Entity\AnotherEntity1'
- 'Acme\BaseBundle\Entity\AnotherEntity2'
- 'Acme\BaseBundle\Entity\AnotherEntity3'
- 'Acme\BaseBundle\Entity\AnotherEntity4'
Run Code Online (Sandbox Code Playgroud)
sol*_*arc 22
我想你需要
$root
->children()
->arrayNode('entities')
->addDefaultsIfNotSet()
->prototype('scalar')->end()
->defaultValue(array(
'Acme\BaseBundle\Entity\DefaultEntity1',
'Acme\BaseBundle\Entity\DefaultEntity2',
))
->end()
Run Code Online (Sandbox Code Playgroud)