繁体   English   中英

覆盖FOSUserBundle表单类型时无法加载类型“XYZ”错误

[英]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

原来我的services.yml文件没有通过依赖注入加载。 挖掘后我意识到我的extension.php文件的这个包名称不正确。 早在我重命名捆绑包时,在重命名DependencyInjection文件夹中的extension.php文件时发了错字。 在纠正错误之后,一切都会再次起作用。

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

public function buildForm(FormBuilder $builder, array $options)
{
    parent::buildForm($builder, $options);

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

如果你在那里进行测试,还要记得清除你的prod缓存......

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM