1.先在模型modules下的LoginForm.php定义一个存储验证码的变量:public $verifyCode;
2.然后再rules()方法里定义:array('verifyCode','captcha','allowEmpty'=>!CCaptcha::checkRequirements());
3.然后再对应的views下的login.php里定义:
<?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 shownin the image above.
< br/>Letters are not case-sensitive.< /div>
< ?php echo $form->error($model,'verif yCode'); ? >
< /div>
< ?phpendif; ? >
4.在login所属控制器中加入:
return array(
// captchaaction renders the CAPTCHA image displayed on the contactpage
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
'maxLength'=>'4',
'minLength'=>'4',
'height'=>'40',
),
);
![Yii日记(verifyCode) django verify code](http://img.aihuau.com/images/01111101/01053655t01f33f5c25fd5651d6.png)