问题描述
我正在使用 Symfony2 的 FOSUserBundle ,并且我需要能够注册用户而无需验证电子邮件是否为唯一,我只需要一个有效的电子邮件,以便许多用户可以拥有相同的电子邮件(我知道这很奇怪,但是我需要)。
I'm using FOSUserBundle for Symfony2, and I need to be able to register a user without validating if the email is Unique, I just need a valid email so many users can have the same email ( I know this is weird, but I need it).
我在扩展FOSUserBundle 的捆绑软件中有一个实体 User,是否可以覆盖emailCanonical的列定义以消除唯一参数并从FormType中删除验证?
I have an entity "User" in a bundle that extends FOSUserBundle, is it possible to overwrite the column definition of emailCanonical to eliminate the unique parameter and remove the validation from the FormType?
我正在使用注释来映射我的实体,并使用YML来验证表单。
I'm using Annotation for mapping my Entities and YML for validation of my forms.
推荐答案
几周前,我遇到了。唯一的解决方案是扩展模型而不是实体:
I had a similar issue few weeks ago. The only solution is to extend model instead of entity:
use FOS\UserBundle\Model\User as BaseUser;
class User extends BaseUser
缺点是您还必须复制从FOS用户实体到您的用户实体的所有内容。另一方面,您可以根据需要调整功能。
The downside is that you have to also copy everything from FOS User entity to your User entity. On the other hand, you can adjust the functionality to your needs.
这篇关于如何覆盖Symfony2捆绑包中的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!