我有一个容器:
$newContainer = new ContainerBuilder();
我加载了一些参数:
$loader = new YamlFileLoader($newContainer, new FileLocator(__DIR__.'/../Resources/config/newFolder'));
$loader->load('newParameters.yml');
我的容器看起来像这样:
[parameters:protected] => Array
(
[exampleKey => Array
(
[parameter] => something value
[anotherParameter] => another value
)
)
现在我进行合并:
$container->merge($newContainer);
我的合并看起来像这样 - print_r($ container):
[parameters:protected] => Array
(
[existing] => Array
(
...
)
[existing2] => Array
(
...
)
[exampleKey => Array
(
[parameter] => something value
[anotherParameter] => another value
)
[existing3] => Array
(
...
)
)
如何合并我的容器所以我有这个?:
[parameters:protected] => Array
(
[existing] => Array
(
...
)
[existing2] => Array
(
...
[exampleKey => Array
(
[parameter] => something value
[anotherParameter] => another value
)
)
[existing3] => Array
(
...
)
)
请帮忙......
答案 0 :(得分:1)
不要使用merge,请使用add():
$container->getParameterBag()
->add(array(
'existing2' => $newContainer->getParameterBag()->all()
));
我不知道在$ container-> getParameterBag()之后隐藏了方法,你可以使用: - > all(),set(),has(),get()等非常有用。感谢