验证fosuserbundle注册表格 [英] validating fosuserbundle registration form

查看:91
本文介绍了验证fosuserbundle注册表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用FOSUserBundle. 在我的项目中,我创建了自己的UserBundle,并覆盖了控制器,表单和处理程序. 现在,当用户尝试使用现有电子邮件进行注册时,该站点将崩溃(电子邮件对于学说来说是唯一的).似乎没有进行验证. 我以为我会在Validation.yml中进行一些验证:

I am using FOSUserBundle. In my project, I created my own UserBundle and overrode the controller, the forms and the handlers. Now when a user tries to register with an existing email, the site crashes (email is unique for doctrine). It seems like there is no validation made. I thought there would be some validation as I have in my validation.yml:

YOP\UserBundle\Entity\User:
  constraints:
    - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: email
  properties:
    email:
      - Email: ~

为什么没有在电子邮件字段上进行验证? 如何确保将验证约束条件考虑在内?

How come the validation isn't made on the email field? How can I make sure that my validation constraints are taken into account?

PS:validation.yml文件不在我的UserBundle中,这有问题吗?

PS: the validation.yml file is not in my UserBundle, is that a problem?

可以在此处获取我的UserBundle的代码. 我不明白为什么现在不再进行验证...

the code of my UserBundle is available here I don't understand why there is no validation done anymore...

推荐答案

通过以下方式解决了该问题:

Solved the issue by:

  • 在与包含我的User实体并指向我的User Entity的包相同的包中包含validate.yml文件
  • 将注册"验证组添加到我的字段中

validation.yml:

validation.yml:

YOP\YourOwnPoetBundle\Entity\User:
  constraints:
    - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: email
  properties:
    email:
      - Email: { groups: [Registration] }
    plainPassword:
      - MinLength: { limit: 5, message: "Your password must have at least {{ limit }} characters" }
    name:
      - NotBlank: { groups: [Registration] }
    familyName:
      - NotBlank: { groups: [Registration] }
    sex:
      - Choice: { choices: [1, 2], groups: [Registration] }
    birthdate:
      - NotNull: { groups: [Registration] }
    city:
      - NotBlank: { groups: [Registration] }
    howDidYouHear:
      - Choice: { choices: [1, 2, 3, 4, 5, 6, 7, 8], groups: [Registration] }

这篇关于验证fosuserbundle注册表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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