无法加载类型“xyz”;重写FOSUserBundle表单类型时出现错误


Could not load type "XYZ" error when overriding FOSUserBundle form types

我试图覆盖Symfony2 FOSUserBundle中的RegistrationFormType。我正在遵循文档,并相信我已经涵盖了所有内容。我已经创建了一个包来包含对FOSUserBundle的覆盖,下面的代码来自这个包以及应用程序配置。

有没有人在重写FOSUserBundle时遇到过这种情况,或者在我的代码中看到任何有助于解释为什么我一直得到这个错误的东西?我正在使用symfony v2.0.4

RegistrationFormType.php

<?php
/*
 * This file is part of the FOSUserBundle package.
 *
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Thrive'SaasBundle'Form'Type;
use Symfony'Component'Form'FormBuilder;
use FOS'UserBundle'Form'Type'RegistrationFormType as BaseType;
class RegistrationFormType extends BaseType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('firstname', null, array('error_bubbling' => true))
            ->add('lastname', null, array('error_bubbling' => true))
            ->add('company', null, array('error_bubbling' => true))
            ->add('email', 'email', array('error_bubbling' => true))
            ->add('username', null, array('error_bubbling' => true))
            ->add('plainPassword', 'repeated', array('type' => 'password', 'error_bubbling' => true))
            ;
    }
    public function getName()
    {
        return 'thrive_user_registration';
    }
}

Services.yml

services:
  thrive_saas_registration.form.type:
    class: Thrive'SaasBundle'Form'Type'RegistrationFormType
    arguments: [%fos_user.model.user.class%]
    tags:
        - { name: form.type, alias: thrive_user_registration}

应用程序的配置文件

fos_user:
     ...
    registration: 
      form:
        type: thrive_user_registration

证明我的服务。没有通过依赖注入加载Yml文件。在深入研究之后,我意识到这个包的extension.php文件命名不正确。早些时候,我重命名了bundle,并在重命名DependencyInjection文件夹中的extension.php文件时犯了一个错别字。纠正拼写错误后,一切又正常了。

您是否尝试添加一个新字段并查看是否有效?

public function buildForm(FormBuilder $builder, array $options)
{
    parent::buildForm($builder, $options);
    // add your custom field
    $builder->add('name');
}