Php 自定义约束验证程序不存在,或无法自动加载
我正在尝试创建自定义约束验证器,但无法使其工作,以下是我遇到的错误:Php 自定义约束验证程序不存在,或无法自动加载,php,symfony,Php,Symfony,我正在尝试创建自定义约束验证器,但无法使其工作,以下是我遇到的错误: AnnotationException: [Semantical Error] The annotation "@Cmpny\MyBundle\Validator\IsGifImage" in property Cmpny\MyBundle\Entity\Post::$src does not exist, or could not be auto-loaded. 以下是我的项目树: src/C
AnnotationException: [Semantical Error] The annotation
"@Cmpny\MyBundle\Validator\IsGifImage" in property
Cmpny\MyBundle\Entity\Post::$src does not exist, or could not be auto-loaded.
以下是我的项目树:
src/Cmpny/MyBundle/Validator/
└── Constraint
├── isGifImage.php
└── isGifImageValidator.php
isGifImage.php
<?php
namespace Appinest\WhenayBundle\Validator\Constraint;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class IsGifImage extends Constraint¬
{
public $message = 'This is not a gif image!';
}
?>
然后在我的实体类中导入:
use Cmpny\WhenayBundle\Validator\Constraint as CmpnyAssert;
然后使用上面我要验证的断言:
@CmpnyAssert\IsGifImage()
我在寻找解决方案,但什么也没找到,有什么帮助吗/ 只是一个想法:重命名您的php脚本(驼峰大小写)第一个字母是小写的“is…”-它可能希望文件的名称与包含的类相同。该死的我!!!谢谢:)如果您愿意,请将您的评论作为答案发布,这样我就可以将我的问题标记为已解决。
@CmpnyAssert\IsGifImage()