Symfony2:第 3 方捆绑包在我的捆绑包中不可用 config.yml
Symfony2: 3rd party bundle is not available in my bundle config.yml
问题
为什么 winzou(第 3 方)配置不适用于我的捆绑包中的 config.yml?
它抛出 'There is no extension able to load the configuration winzou...'
更新
http://symfony.com/doc/current/cookbook/bundles/prepend_extension.html
看起来这就是我想要发生的最终结果 - 像 prepended/appended 一样对待应用程序 config.yml。
我可以加载文件并在前面添加它。但我觉得 symfony 已经允许为每个包加载额外的配置。必须有一种更简单的方法来加载它。
我加载 winzou 状态机包:
/app/AppKernel.php
new winzou\Bundle\StateMachineBundle\winzouStateMachineBundle(),
然后我从我的包 (OrderBundle) 中加载一个配置。
/src/OrderBundle/DependencyInjection/OrderExtension.php
class OrderExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('config.yml');
}
}
如果我将状态机配置放入 OrderBundle 配置中:
/src/OrderBundle/Resources/config/config.yml
winzou_state_machine:
order_state_machine:
...
抛出异常:
There is no extension able to load the configuration for "winzou_state_machine" (in [...]/OrderBundle/DependencyInjection/../Resources/config/config.yml). Looked for namespace "winzou_state_machine", found none
如果我将状态机配置放在根应用程序文件夹中就可以了。
/app/config/config.yml
它不起作用,因为 bundle 扩展的加载方法负责加载与其所属的 bundle 相关的服务配置,并且仅用于此目的。您作为 load 方法的参数获得的容器只是应用程序容器的副本,它不包含所有内容(仅包含参数)[#using-the-load-method]。
Using the load() Method
In the load() method, all services and parameters related to this extension will be loaded. This method doesn't get the actual container instance, but a copy. This container only has the parameters from the actual container. After loading the services and parameters, the copy will be merged into the actual container, to ensure all services and parameters are also added to the actual container.
如您所说,您可以使用 prepend 方法为其他包提供合理的默认配置并简化您的包的使用 [prepend_extension]。
问题
为什么 winzou(第 3 方)配置不适用于我的捆绑包中的 config.yml?
它抛出 'There is no extension able to load the configuration winzou...'
更新
http://symfony.com/doc/current/cookbook/bundles/prepend_extension.html
看起来这就是我想要发生的最终结果 - 像 prepended/appended 一样对待应用程序 config.yml。
我可以加载文件并在前面添加它。但我觉得 symfony 已经允许为每个包加载额外的配置。必须有一种更简单的方法来加载它。
我加载 winzou 状态机包:
/app/AppKernel.php
new winzou\Bundle\StateMachineBundle\winzouStateMachineBundle(),
然后我从我的包 (OrderBundle) 中加载一个配置。 /src/OrderBundle/DependencyInjection/OrderExtension.php
class OrderExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('config.yml');
}
}
如果我将状态机配置放入 OrderBundle 配置中: /src/OrderBundle/Resources/config/config.yml
winzou_state_machine:
order_state_machine:
...
抛出异常:
There is no extension able to load the configuration for "winzou_state_machine" (in [...]/OrderBundle/DependencyInjection/../Resources/config/config.yml). Looked for namespace "winzou_state_machine", found none
如果我将状态机配置放在根应用程序文件夹中就可以了。
/app/config/config.yml
它不起作用,因为 bundle 扩展的加载方法负责加载与其所属的 bundle 相关的服务配置,并且仅用于此目的。您作为 load 方法的参数获得的容器只是应用程序容器的副本,它不包含所有内容(仅包含参数)[#using-the-load-method]。
Using the load() Method
In the load() method, all services and parameters related to this extension will be loaded. This method doesn't get the actual container instance, but a copy. This container only has the parameters from the actual container. After loading the services and parameters, the copy will be merged into the actual container, to ensure all services and parameters are also added to the actual container.
如您所说,您可以使用 prepend 方法为其他包提供合理的默认配置并简化您的包的使用 [prepend_extension]。