验证fosuserbundle注册表

fko*_*ler 1 validation symfony fosuserbundle

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

YOP\UserBundle\Entity\User:
  constraints:
    - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: email
  properties:
    email:
      - Email: ~
Run Code Online (Sandbox Code Playgroud)

为什么不在电子邮件领域进行验证?如何确保考虑我的验证限制?

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

编辑:

我的UserBundle的代码在这里可用 我不明白为什么不再进行验证...

fko*_*ler 6

解决了这个问题:

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

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] }
Run Code Online (Sandbox Code Playgroud)