Reputation: 2103
Just going through symblog.co.uk symfony2 tutorial. i'm kind of stuck in validations. At first it kept giving erros but i found this article in which author corrects mistakes which source is tutorial being old. anyway, article tells me to change validator in
src/Blogger/BlogBundle/Entity/Enquiry.php:
from
$metadata->addPropertyConstraint('body', new MaxLength(50));
to:
$metadata->addPropertyConstraint('body', new Length(array('min'=> 50)));
It works, yay! Same way i changed
$metadata->addPropertyConstraint('subject', new MaxLength(50));
into
$metadata->addPropertyConstraint('subject', new Length(array('max'=>50)));
But this time there is no validation performed. Where is the mistake? How should maximum-length validation looks like?
Upvotes: 3
Views: 4546
Reputation: 1006
According to the docs
use Symfony\Component\Validator\Constraints as Assert;
…
$metadata->addPropertyConstraint('firstName', new Assert\Length(array(
'min' => 2,
'max' => 10
)));
Upvotes: 4