FOSUserBundle用户名表单字段

原文地址: http://symfony.com/doc/current/bundles/FOSUserBundle/form_type.html

FOSUserBundle提供了一个名为fos_user_username的用户名表单字段. 它是一个文本输入框, 接受用户名并且将其添加至用户实例中:

1
2
3
4
5
6
7
8
9
10
class MessageFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('recipient', 'FOS\UserBundle\Form\Type\UsernameFormType');

// if you are using Symfony < 2.8 you should use the old name instead
// $builder->add('recipient', 'fos_user_username');
}
}

假如你不想在应用中使用这种表单字段, 可以删除容器服务中的配置来禁用它:

# app/config/config.yml
fos_user:
    use_username_form_type: false