So I have this custom validator in Symfony2.4,
namespace My\Bundle\validation\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class CustomValidator extends Constraint {
/**
* @var str the message to display if violation
*/
public $message = "the message";
/**
* {@inheritdoc}
*/
public function validatedBy()
{
return 'my_validator_service';
}
/**
* {@inheritdoc}
*/
public function getTargets()
{
return self::PROPERTY_CONSTRAINT;
}
}
Now, in a different bundle FormType:
.....
use My\Bundle\Validation\Constraints;
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$collectionConstraint = new Assert\Collection(array(
.......,
'test' => array(
new CustomValidator(),
),
........
$resolver->setDefaults(array(
'constraints' => $collectionConstraint,
'data' => $data,
));
}
But I got this exception:
ClassNotFoundException: Attempted to load class "CustomValidator" from namespace "My\Bundle\Validation\Constraints" in blabla\Type. Do you need to "use" it from another namespace?
What do you think? Probably is is something trivial but I don't know what it could be