【发布时间】:2015-05-18 22:23:20
【问题描述】:
我尝试使用我的包中的 prependExtensionConfig 将配置数组添加到不同的包。在 $config 被硬编码之前一切正常。
我的目标是使用 service (例如来自数据库)加载 $config 值,然后将其添加到其他包中。
问题是当时没有加载服务。 我猜这是 symfony2 的一个限制。
有什么想法吗?谢谢
class MyExtension extends Extension implements PrependExtensionInterface
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
}
public function prepend(ContainerBuilder $container)
{
$config = // load config from a service ...
$container->prependExtensionConfig('other_bundle', $config);
}
}
【问题讨论】:
-
在加载扩展之前调用 prepend 方法,因此此时不会加载服务。设置参数没有帮助。
-
你读过我链接的问题吗?我可以再次解释同样的情况。但它会重复链接问题的答案。
-
谢谢。是的,但如果我理解正确的话 prependExtensionConfig 和 setParameter 是不同的东西。试过了,因为加载顺序不工作。我想这是一个限制,我必须围绕它进行构建。
-
好的。我稍后会回答你的问题...