The example of this article describes the implementation method of adding verification code in YII2. Share to everyone for your reference, specific as follows:
First, add the validation code field to the model:
Public Function rules () {return
[' Verifycode ', ' captcha '],
}
Second, you can add the field name of the validation code in the foreground page in the function Attributelabels:
Public Function Atrributelabels () {return
[' Verifycode ' => ' verification Code ',];
}
Then, in the view file, make the following modifications:
Use Yii\captcha\captcha;
<?= $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 > ',
])?>
I hope this article will help you with the PHP program design based on the YII framework.