I am using Symfony 2.0.12 and trying to create a custom constraint.
I have read the official documentation and some Stack Overflow questions but they don't help me...
I've created a file called Nif.php in Bundle/Validator/Constraints with the following content:
<?php
namespace XX\YYBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class NIF extends Constraint
{
public $message = 'El NIF introducido no es válido';
}
Then a file called NIFValidator.php in the same directory with the following content:
<?php
namespace XX\YYBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
class NIFValidator extends ConstraintValidator
{
public function isValid($value, Constraint $constraint)
{
[...]
}
}
And in the entity I import the validator with
use XX\YYBundle\Validator\Constraints as XXAssert;
and use it with the property...
/**
@XXAssert/NifValidator()
**/
But it doesn't seems to validate... I also tried to add a die;
in the validator but the page seems to render without any problem...
Any thoughts?