Yii框架中验证码的简单使用介绍
Yii框架中验证码的简单使用介绍1.在controller中修改:public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,//背景颜色
'minLength'=>4,//最短为4位
'maxLength'=>4, //是长为4位
'transparent'=>true,//显示为透明
),
);
}2.在view的form表单中添加如下代码:<?php if(CCaptcha::checkRequirements()): ?>
<div>
<?php echo $form->labelEx($model,'verifyCode'); ?>
<div>
<?php $this->widget('CCaptcha'); ?>
<?php echo $form->textField($model,'verifyCode'); ?>
</div>
<div>Please enter the letters as they are shown in the image above.
<br/>Letters are not case-sensitive.</div>
<?php echo $form->error($model,'verifyCode'); ?>
</div>
<?php endif; ?>3.如果想要检测验证码是否正确的话还要在相关的model类的rules方法中指定相关verifyCode的验证机制captcha,或者也可以通过调用CCaptchaValidator类的validate方法实现验证。
页:
[1]