yii实现创建验证码实例解析
本文以实例形式讲述了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', ), );
二、(1)在LoginForm model rules()下添加代码:
//captche class needed array('verifyCode', 'captcha','allowEmpty'=>!CCaptcha::checkRequirements()),
(2)LoginForm model下添加属性:
public $verifyCode;
三、在ContactForm model rules()下添加代码:
// verifyCode needs to be entered correctly array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
四、在login view下添加代码:
<div class="row"> <?php echo $form->labelEx($model,'verifyCode'); ?> <?php $this->widget('CCaptcha'); ?> <?php echo $form->textField($model,'verifyCode'); ?> <?php echo $form->error($model,'verifyCode'); ?> </div>
本例代码仅为主要功能简述,读者还可以根据自身项目需求进一步完善该程序代码,使其功能更具实用性。
相关推荐
WasteLand 2020-10-18
Allinputs 2020-08-30
Ashes 2020-06-14
caiyiii 2020-06-14
kxguan 2020-06-14
daillo 2020-06-14
一粒沙里的世界 2020-06-14
ruxingli 2020-06-14
csssy00 2020-06-14
阿佐 2020-06-14
NameWFY 2020-05-28
NameWFY 2020-05-26
Robin罗兵 2020-05-16
caiyiii 2020-04-29
wmsjlihuan 2020-04-26
cbao 2020-04-26
csssy00 2020-04-19
igogo00 2020-03-09