覆盖注册FOSUserBundle Symfony2

覆盖注册FOSUserBundle Symfony2,symfony,Symfony,我试图覆盖FOSUserBundle中的注册表,但出现以下错误: 我在官方文档中遵循了本教程: 我的档案是: 服务.yml # src/Uae/UserBundle/Resources/config/services.yml services: uae_user.registration.form.type: class: Uae\UserBundle\Form\Type\RegistrationFormType arguments: [%fos_us

我试图覆盖FOSUserBundle中的注册表,但出现以下错误: 我在官方文档中遵循了本教程:

我的档案是: 服务.yml

# src/Uae/UserBundle/Resources/config/services.yml 
services:
    uae_user.registration.form.type:
        class: Uae\UserBundle\Form\Type\RegistrationFormType
        arguments: [%fos_user.model.user.class%]
        tags:
        - { name: form.type, alias: uae_user_registration }
config.yml:

app/config/config.yml 注册表单类型:

<?php
#src/Uae/UserBundle/Form/Type/RegistrationType.php

namespace Uae\UserBundle\Form\Type;

use Symfony\Component\Form\FormBuilderInterface;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;

class RegistrationFormType extends BaseType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
    parent::buildForm($builder, $options);

    // add your custom field
    $builder->add('nom');
    $builder->add('prenom');
}

public function getName()
{
    return 'uae_user_registration';
}
}
我解决了我的问题:
我刚刚导入了在配置文件中创建的新服务
app\config\config.yml

imports:
    - { resource: @UaeUserBundle/Resources/config/services.yml }

出现错误的原因是您没有针对特定捆绑包的DependencyInjection。程序不知道在哪里查找services.yml文件

在用户包下的DependencyInjection文件夹中,需要一个UaeUserExtension.php和Configuration.php

解决这个问题的简单方法是通过app/console-generate:bundle生成捆绑包。这样,它会自动为您创建DependencyInjection

手动解决方案是在您的Uae/UserBundle中创建DependencyInjection文件夹。在DependencyInjection内部,创建一个名为Configuration.php的文件,并将内容放在下面:

<?php

namespace Uae\UserBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
    /**
     * {@inheritDoc}
     */
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('uae_user');

        return $treeBuilder;
    }
}

如果您回答了自己的问题,请单击答案旁边的复选标记来标记已回答的问题。
imports:
    - { resource: @UaeUserBundle/Resources/config/services.yml }
<?php

namespace Uae\UserBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
    /**
     * {@inheritDoc}
     */
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('uae_user');

        return $treeBuilder;
    }
}
<?php

namespace Uae\UserBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

class EnergyUserExtension extends Extension
{
    /**
     * {@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');
    }
}