簡體   English   中英

自定義約束驗證器不存在,或無法自動加載

[英]Custom constraint validator does not exist, or could not be auto-loaded

我正在嘗試創建一個自定義約束驗證器,但無法使其正常工作,這是我遇到的錯誤:

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!';
}
?>

isGifImageValidator

  3 namespace Appinest\WhenayBundle\Validator\Constraint;¬
  2 ¬
  1 use Symfony\Component\Validator\Constraint;¬
  0 use Symfony\Component\Validator\ConstraintValidator;¬
  1 ¬
  2 class IsGifImageValidator extends ConstraintValidator¬
  3 {¬
  4     public function isValid($value, Constraint $constraint)¬
  5     {¬
  6         //My function
 22     }¬
    }

然后在我的實體類中導入:

use Cmpny\WhenayBundle\Validator\Constraint as CmpnyAssert;

然后在我要驗證的內容之上使用斷言:

@CmpnyAssert\IsGifImage()

我搜索了解決方案,但沒有找到任何幫助? :/

只是想一想:重命名您的php腳本(駝峰大小寫),第一個字母為小寫的'is ...'-它可能期望文件名與所包含的類相同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM