Home >Backend Development >PHP Tutorial >Implementation method of adding verification code in yii2

Implementation method of adding verification code in yii2

WBOY
WBOYOriginal
2016-07-29 09:07:13997browse

The example in this article describes the implementation method of adding verification code in yii2. Share it with everyone for your reference, as follows:

First, add the verification code field in the model:

public function rules(){
return ['verifyCode', 'captcha'],
}

Secondly, you can add the field name of the verification code in the front page in the function attributeLabels:

public function atrributeLabels(){
return ['verifyCode'=>'Verification Code', ];
}

Then , make the following modifications in the view file:

use yii\captcha\Captcha;
<&#63;= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
          'template' => '<div><div>{image}</div><div>{input}</div></div>',
 ]) ?>

I hope this article will be helpful to everyone’s PHP program design based on the Yii framework.

The above introduces the implementation method of adding verification code in yii2, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn