Yii登陆添加验证码

来源:互联网 发布:mac下载汉仪颜体 编辑:程序博客网 时间:2024/05/01 04:33
添加带验证码的登陆:
1.先在模型modules下的LoginForm.php定义一个存储验证码的变量:public $verifyCode;

2.然后在rules()方法里定义:array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements());

3.然后在对应视图views下的login.php里定义:
    <?php if(CCaptcha::checkRequirements()): ?>
        <div class="row">
                <?php echo $form->labelEx($model,'verifyCode'); ?>
                <div>
                <?php $this->widget('CCaptcha'); ?>
                <?php echo $form->textField($model,'verifyCode'); ?>
                </div>
                <div class="hint">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; ?>
4.在login所属的的控制器中加入:
public function actions() {$array = array(    'captcha' => array('class' => 'CCaptchaAction','backColor' => 0xFFFFFF,                'minLength'=>4,  //最短为4位                'maxLength'=>4,   //是长为4位                'transparent'=>true,  //显示为透明    ));return $array;    }
0 0
原创粉丝点击