ClassNotFoundException Symfony2验证程序
我在Symfony2.4中有一个自定义验证器ClassNotFoundException Symfony2验证程序,class,validation,symfony,exception,Class,Validation,Symfony,Exception,我在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 = "th
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;
}
}
现在,在另一个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,
));
}
但我有一个例外:
ClassNotFoundException:试图从blabla\Type中的命名空间“My\Bundle\Validation\Constraints”加载类“CustomValidator”。是否需要从另一个命名空间“使用”它
你觉得怎么样?可能是一些琐碎的事情,但我不知道它可能是什么也许您应该在中更改您的使用指令:
use My\Bundle\Validation\Constraints\CustomValidator;
好的,我找到了。
命名空间和用法是正确的,但Folder被称为Validator而不是Validation。
抱歉,我已经尝试了各种组合,使用
作为,或者不同的名称。但是没有结果。