gpt4 book ai didi

configuration - 使用 Symfony2 配置类,如何定义其子节点没有键的数组节点?

转载 作者:行者123 更新时间:2023-12-04 09:26:34 24 4
gpt4 key购买 nike

使用配置类,如何定义一个没有数字键的数组节点?阵列的 child 不代表进一步的配置选项。相反,它们将是一个不能被选择性覆盖的列表,只能作为一个整体。

到目前为止,我有:

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;
}

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()

关于configuration - 使用 Symfony2 配置类,如何定义其子节点没有键的数组节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11937710/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com