yii 验证码不显示图片怎么办?
yii2中验证码的使用-图片不显示
推荐学习:yii框架
1.控制器中
public function actions() { return [ 'captcha' => [ 'class' => 'yii\captcha\CaptchaAction', 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, ], ]; }
2.模型中
要有一个验证码的字段$verifyCode
3.视图中
use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\captcha\Captcha;
自动生成表单
页面中验证码代码
= $form->field($model, 'verifyCode')->widget(Captcha::className(), [ 'template' => '', ]) ?>{image}{input}
控制器中的权限可能导致验证码图片不显示,
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'signup','login'],
'rules' => [
[
'actions' => ['signup'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
控制器中红线部分缺少则导致验证码不显示。
Atas ialah kandungan terperinci yii 验证码不显示图片怎么办. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!