1

When I am trying to validate my user entity form after posting I am getting a

ContextErrorException: Catchable Fatal Error: Argument 1 passed to Symfony\Component\Validator\Mapping\ClassMetadata::addConstraint() must be an instance of Symfony\Component\Validator\Constraint, array given

It is true that it is a array as it is defined like this in validation.yml

Transplan\CoreBundle\Entity\User:
  constraints:
    \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: { fields: [company, username], message: "Brugernavnet er allerede taget" }

But how do I get the validator to understand that this is how you specify constaints in yml according to http://symfony.com/doc/current/reference/constraints/UniqueEntity.html

My form is created like this

$user = new User();
$createUserForm = $this->createFormBuilder($user)
   ->add('username', 'text')
   ->add('name', 'text')
   ->add('Opret', 'submit')
   ->getForm();

1 Answer 1

5

you're missing the - in front of the constraint.

Transplan\CoreBundle\Entity\User:
    constraints:
        - \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: [company, username]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.