控制器
public function actionCheckLogin(){
if(!$this->createAction('verify_code')->validate($_POST['verfiy_code'], false)){
$error = '验证码不正确';
}
}
/*
或者打印出正确的验证码 $captch= new CCaptchaAction($this,'verify_code');
echo $right = $captch->getVerifyCode();
然后比对用户提交的验证码
*/
public function actions(){
return array(
'verify_code' => array(
'class' => 'CCaptchaAction',
'backColor'=>0xFFFFFF,
'minLength' => 4,
'maxLength' => 4,
'width' => 78,
'height' => 30,
),
);
}
视图
<a class="code-img">
<?php $this->widget('CCaptcha', array('captchaAction' => 'verify_code', 'imageOptions'=>array('class' => 'verfiy_code'), 'buttonOptions' => array('class' => 'refresh_verfiy_code'), 'buttonLabel' => '<br>点击刷新'));?>
</a>