yii2中添加验证码的实现方法_php实例

WBOY
Release: 2016-06-07 17:09:53
Original
702 people have browsed it

本文实例讲述了yii2中添加验证码的实现方法。分享给大家供大家参考,具体如下:

首先,在模型中添加验证码字段:

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

Copy after login

其次,可以在函数attributeLabels中添加前台页面中验证码的字段名称:

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

Copy after login

然后,在视图文件中做如下修改:

use yii\captcha\Captcha;
<&#63;= $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>',
 ]) &#63;>

Copy after login

希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template