#yii What should I do if the verification code does not display the picture?
Use of verification code in yii2 - the picture is not displayed
Recommended learning: yii framework
1. In the controller
public function actions() { return [ 'captcha' => [ 'class' => 'yii\captcha\CaptchaAction', 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, ], ]; }
2. There must be a verification code field in the model $verifyCode
3. In the view,
use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\captcha\Captcha;
automatically generates a form
Verification code code in the page
<?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [ 'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>', ]) ?>
Permissions in the controller may cause the verification code image not to be displayed,
public function behaviors(){
'access' => 'only' => ['logout', 'signup','login'],
'rules' => Actions' = & gt; ['signup'], # 'all' = & gt; true, 'roles' = & gt; ['? '],##] , [
'Actions' = & GT; ['Logout'],
'Alow' = & GT; TRUE,
## 'ROLES' = > ['@'], # # .
The above is the detailed content of What should I do if the yii verification code does not display pictures?. For more information, please follow other related articles on the PHP Chinese website!