gpt4 book ai didi

symfony - 将Symfony2服务配置移至捆绑

转载 作者:行者123 更新时间:2023-12-03 11:44:10 27 4
gpt4 key购买 nike

我的config.yml中有以下内容

services:
my.user_provider:
class: Acme\MySecurityBundle\Security\UserProvider

但想将其移动到我的 MySecurityBundle/Resources/config中的config.yml中,但是Symfony2告诉我在移动它时该服务不存在。

我如何从那里拿起 config.yml文件?

最佳答案

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

关于symfony - 将Symfony2服务配置移至捆绑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8317817/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com