symfony2:从FOSUserBundle注册表中删除用户名无效

时间:2015-07-06 20:29:21

标签: php symfony fosuserbundle

我尝试从this answer中的步骤2中所述的FOSUserBundle注册表单中删除用户名字段。

这是我为了覆盖默认值而创建的FormType类:

<?php

// src/UserBundle/Form/Type/RegistrationFormType.php

namespace UserBundle\Form\Type;

use FOS\UserBundle\Form\Type\RegistrationFormType as BaseFormType;

class RegistrationFormType extends BaseFormType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        parent::buildForm($builder, $options);
        $builder->remove('username');
    }
}

然而,用户名字段仍显示在表单中。我错过了什么?

1 个答案:

答案 0 :(得分:1)

您没有覆盖捆绑包配置中的表单服务。

这就是为什么FOSUserBundle不使用您的表单类型。

# register your form-type as a service ...
services:
    my_custom_user_registration_form:
        class:  "UserBundle\Form\Type\RegistrationFormType"

# ... then tell FOSUserBundle to use this form-type service instead of the default
fos_user:
    ...
    registration:
        form:
            type: my_custom_user_registration_form
相关问题