<?php echo $form->field($model, 'captcha')->widget(Captcha::className(), [
]); ?>
在yii2要求中传递了要求,如GD和imagick liberies,但验证码图像没有显示。
答案 0 :(得分:2)
} else {
ob_clean(); //Add this line, can solve this problem. Or add in other suitable places
$this->setHttpHeaders();
Yii::$app->response->format = Response::FORMAT_RAW;
return $this->renderImage($this->getVerifyCode());
}
这会有所帮助, 请更改\ vendor \ yiisoft \ yii2 \ captcha \ CaptchaAction.php并显示图片。
答案 1 :(得分:0)
你必须设置验证码&#39;模型中的规则。
['captcha', 'captcha', 'captchaAction' => 'site/captcha']
第一个验证码是您的财产,下一个是规则类型
务必设置控制器
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
答案 2 :(得分:0)
} else {
ob_clean(); //Add this line, can solve this problem. Or add in other suitable places
$this->setHttpHeaders();
Yii::$app->response->format = Response::FORMAT_RAW;
return $this->renderImage($this->getVerifyCode());
}