2016-11-27 3 views
2

私のアプリではsymfony-2.8をsymfony-captcha-bundleとともに使用しています。私のユーザーエンティティは登録プロセス中にcaptcha検証を行い、期待どおりに動作します。 私はユーザーオブジェクトの更新を行った後、アプリがエラーを返した場合:特定のアクション/コンテキスト(登録および更新なし)に対してのみ、検証制約(Captcha Assert)の使用を制限する方法

request.CRITICAL: Uncaught PHP Exception 
Symfony\Component\Debug\Exception\ContextErrorException: "Catchable Fatal Error: 
Argument 1 passed to Captcha\Bundle\CaptchaBundle\Helpers\BotDetectCaptchaHelper::__construct() must implement interface 
Symfony\Component\HttpFoundation\Session\SessionInterface, null given, called in C:\apps\Apache24\htdocs\WodProject\vendor\captcha-com\symfony-captcha-bundle\Integration\BotDetectCaptcha.php 
on line 68 and defined" at C:\apps\Apache24\htdocs\WodProject\vendor\captcha-com\symfony-captcha-bundle\Helpers\BotDetectCaptchaHelper.php 
line 26 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\ContextErrorException(code: 0): 
Catchable Fatal Error: Argument 1 passed to Captcha\\Bundle\\CaptchaBundle\\Helpers\\BotDetectCaptchaHelper::__construct() 
must implement interface Symfony\\Component\\HttpFoundation\\Session\\SessionInterface, null given, called in C:\\apps\\Apache24\\htdocs\\WodProject\\vendor\\captcha-com\\symfony-captcha-bundle\\Integration\\BotDetectCaptcha.php 
on line 68 and defined at C:\\apps\\Apache24\\htdocs\\WodProject\\vendor\\captcha-com\\symfony-captcha-bundle\\Helpers\\BotDetectCaptchaHelper.php:26)"} [] 

キャプチャの検証をユーザエンティティへ:

/** 
* @CaptchaAssert\ValidCaptcha(
* message = "registration.errorCatpcha" 
*) 
*/ 
protected $captchaCode; 

私はこの問題は、制約が常にトリガされていることだと思い。私はどのようにユーザーの登録中に制約をアクティブにし、他のアクション(更新など)で無効にするかを知る必要があります。

答えて

1

ジャスト(アノテーションを使用して)以下の例のような制約に検証グループを割り当てる:

ニーズによってによって
/** 
* @CaptchaAssert\ValidCaptcha(
*  message = "registration.errorCatpcha", 
*  groups={"registration"} <--- VALIDATION GROUP 
*) 
*/ 
protected $captchaCode; 

あなたは異なる形で特定のアサートを使用する1つのまたは複数の検証グループを追加することができます

+0

パーフェクト!できます! – Frodogus

関連する問題