验证fosuserbundle注册表

时间:2012-09-05 07:16:18

标签: validation symfony fosuserbundle

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

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

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

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

编辑:

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

2 个答案:

答案 0 :(得分:6)

通过以下方式解决问题:

  • 将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] }

答案 1 :(得分:-1)

validation.yml应该在您的用户捆绑中 /app/config/config.yml应更新如下:

validation:      { enabled: true,  enable_annotations: false }