使用配置类,如何定义没有数字键的数组节点?数组的子项不代表进一步的配置选项。相反,它们将是一个无法选择性覆盖的列表,只能作为一个整体进行覆盖。
到目前为止我有:
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
,我希望能够像这样覆盖它:
acme_base:
entities:
- 'Acme\BaseBundle\Entity\AnotherEntity1'
- 'Acme\BaseBundle\Entity\AnotherEntity2'
- 'Acme\BaseBundle\Entity\AnotherEntity3'
- 'Acme\BaseBundle\Entity\AnotherEntity4'
我想你需要
$root
->children()
->arrayNode('entities')
->addDefaultsIfNotSet()
->prototype('scalar')->end()
->defaultValue(array(
'Acme\BaseBundle\Entity\DefaultEntity1',
'Acme\BaseBundle\Entity\DefaultEntity2',
))
->end()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)