Symfony2:如何使FOSUserBundle用户的用户名唯一 [英] Symfony2: How to make username of FOSUserBundle user unique

查看:59
本文介绍了Symfony2:如何使FOSUserBundle用户的用户名唯一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有自己的User类,该类继承了FOS\UserBundle\Entity\User.另外,我编写了自己的注册例程.现在,我有一个问题,即表单不能确保用户名是唯一的.我总是得到:

I have my own User Class, which inherits FOS\UserBundle\Entity\User. Additionally I wrote my own registration routine. Now I have the problem that the form does not make sure that the username is unique. I always get:

SQLSTATE [23000]:违反完整性约束:1062键"UNIQ_2DA1797792FC23A8"的条目"myusername"重复

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'myusername' for key 'UNIQ_2DA1797792FC23A8'

我尝试按照文档中的说明添加@UniqueEntity("email")注释 1 ,但没有任何效果.

I tried adding the @UniqueEntity("email") annotation as stated in the documentation1, but without any effect.

有人知道怎么了吗?

推荐答案

约束已存在于FOS捆绑包中.您可能需要将表单上的validation_groups选项设置为array('Registration').

The constraint exists in the FOS bundle already. You probably need to set the validation_groups option on your form to array('Registration').

这篇关于Symfony2:如何使FOSUserBundle用户的用户名唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆