Symfony2: my form returns false from isValid() but empty array for getErrors() from unique constraint condition

前端 未结 6 853
天命终不由人
天命终不由人 2021-02-13 04:02

I have a Customer entity that only has a unique Email field to it. I am trying to edit a customer\'s email and the validation works fine. However I have this in my controller:

6条回答
  •  一生所求
    2021-02-13 04:38

    Ok, found an answer here:

    Symfony2 invalid form without errors

    It turns out each form child has it's own separate errors. When doing a var_dump of

    $editForm->getChildren()['email']->getErrors()
    

    I get:

    array (size=1)
      0 => 
        object(Symfony\Component\Form\FormError)[531]
          private 'message' => string 'A customer under that email address already exists' (length=50)
          protected 'messageTemplate' => string 'A customer under that email address already exists' (length=50)
          protected 'messageParameters' => 
            array (size=0)
              empty
          protected 'messagePluralization' => null
    

    I am still wondering how to determine that the error is because of a unique conflict without parsing the error message string.

提交回复
热议问题