本文介绍了将 Symfony2 服务配置移动到 bundle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 config.yml 中有以下内容
I have the following in my config.yml
services:
my.user_provider:
class: Acme\MySecurityBundle\Security\UserProvider
但想将其移动到我的 MySecurityBundle/Resources/config
中的 config.yml 但 Symfony2 告诉我移动时该服务不存在.
but would like to move this to config.yml in my MySecurityBundle/Resources/config
but Symfony2 tells me that the service doesn't exist when I move it.
如何让它从那里获取 config.yml
文件?
How do I get it to pick up the config.yml
file from there?
推荐答案
src/Acme/MySecurityBundle/DependencyInjection/MySecurityExtension.php
:
<?php
namespace Acme\MySecurityBundle\DependencyInjection;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;
class MySecurityExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
src/Acme/MySecurityBundle/Resources/config/services.yml
:
services:
my_security.user_provider:
class: Acme\MySecurityBundle\Security\UserProvider
这篇关于将 Symfony2 服务配置移动到 bundle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!