Configuration 使用Symfony2配置类,如何定义其子节点不';你没有钥匙吗?

Configuration 使用Symfony2配置类,如何定义其子节点不';你没有钥匙吗?,configuration,symfony,Configuration,Symfony,使用configuration类,如何定义没有数字键的数组节点?数组的子项不表示进一步的配置选项。相反,它们将是一个无法选择性覆盖的列表,只能作为一个整体覆盖 到目前为止,我已经: public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder; $root = $treeBuilder->root('acme_base'); $root ->children()

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

到目前为止,我已经:

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

我刚刚在别的地方找到了
原型
方法。但是你需要添加<代码> ->结尾()/代码>,比如<代码> >原型(‘标量’)->结束()/代码>,否则<代码> >默认值(值)将应用到每个数组项。谢谢你告诉我关于代码> > AddiDebug(非Adbug)(<代码)>。