Home > Backend Development > PHP Tutorial > yii实现创建验证码实例解析_PHP

yii实现创建验证码实例解析_PHP

WBOY
Release: 2016-05-31 19:31:00
Original
848 people have browsed it

本文以实例形式讲述了yii创建验证码的方法,具体步骤如下所示:

一、在SiteController action()下添加如下代码:

return array(
 // captcha action renders the CAPTCHA image displayed on the contact page
 'captcha'=>array(
 'class'=>'CCaptchaAction',
 'backColor'=>0xFFFFFF,
 ),
 // page action renders "static" pages stored under 'protected/views/site/pages'
 // They can be accessed via: index.php?r=site/page&view=FileName
 'page'=>array(
 'class'=>'CViewAction',
 ),
);
Copy after login

二、(1)在LoginForm model rules()下添加代码:

//captche class needed
array('verifyCode', 'captcha','allowEmpty'=>!CCaptcha::checkRequirements()),
Copy after login

(2)LoginForm model下添加属性:

public $verifyCode;
Copy after login

三、在ContactForm model rules()下添加代码:

// verifyCode needs to be entered correctly
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
Copy after login

四、在login view下添加代码:

<div class="row">
<&#63;php
echo $form->labelEx($model,'verifyCode');
&#63;>
<&#63;php
$this->widget('CCaptcha');
&#63;>
<&#63;php
echo $form->textField($model,'verifyCode');
&#63;>
<&#63;php
echo $form->error($model,'verifyCode');
&#63;>
</div>
Copy after login

本例代码仅为主要功能简述,读者还可以根据自身项目需求进一步完善该程序代码,使其功能更具实用性。

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