0

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

2 Answers 2

1

Ok so I found it. namespace and use was correct, but the folderwas called Validator instead of Validation. Sorry all

Sign up to request clarification or add additional context in comments.

Comments

0

Maybe you should change your use directive in:

use My\Bundle\Validation\Constraints\CustomValidator;

1 Comment

I already tried various combinations, using as, or different names. But with no result.

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.