4

我正在尝试覆盖 FOSUserBundle 中的注册表单,但出现此错误:我已按照官方文档中的本教程进行操作: 链接

Could not load type "uae_user_registration"

我的文件是:services.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 }

配置.yml:

应用程序/配置/config.yml

fos_user:
    db_driver:     orm                         
    firewall_name: main                       
    user_class:    Uae\UserBundle\Entity\User 
    registration:
            form:
                type: uae_user_registration

注册表格类型:

<?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';
}
}
4

2 回答 2

9

我解决了我的问题:我刚刚导入了我在配置文件 app\config\config.yml 中创建的新服务

imports:
    - { resource: @UaeUserBundle/Resources/config/services.yml }
于 2012-06-11T16:19:40.067 回答
6

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

您需要在 User Bundle 下的 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;
    }
}

并在同一目录中创建一个名为 UaeUserExtension.php 的文件并将这些内容放入其中:

<?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');
    }
}
于 2012-06-13T23:39:38.137 回答