1

I use Doctrine 2 and Symfony 2 Validator Component (standalone, without Forms Component).

So, when I finish checking the Doctrine Entity and pass it to SF2 Validator, I need to add custom error message to the validator. How can I do that?

This is my code so far:

$validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
$errors = $validator->validate($entry);

// Add custom error will be here
$errors->add(new ConstraintViolation("Error text maybe here"));

1 Answer 1

3

It should looks like this:

$error = new ConstraintViolation('Error message', '', [], $entity, 'fieldName', 'value that caused this violation');
$errors->add($error);
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.