一:打开文件 /framework/web/widgets/captcha/CCaptchaAction.php
添加全局变量public $toRefresh=false;
修改run方法,增加红色部分代码
public function run()
{
if(isset($_GET[self::REFRESH_GET_VAR])) // AJAX request for regenerating code
{
$code=$this->getVerifyCode(true);
echo CJSON::encode(array(
'hash1'=>$this->generateValidationHash($code),
'hash2'=>$this->generateValidationHash(strtolower($code)),
// we add a random 'v' parameter so that FireFox can refresh the image
// when src attribute of image tag is changed
'url'=>$this->getController()->createUrl($this->getId(),array('v' => uniqid())),
));
}elseif($this->toRefresh){
$code=$this->getVerifyCode(true);
$this->renderImage($code);
}
else
$this->renderImage($this->getVerifyCode());
Yii::app()->end();
}
二:控制器增加下面红色代码
public function actions()
{
return array(
//验证码
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
'maxLength'=>4,
'minLength'=>4,
'width'=>80,
'height'=>36,
'toRefresh' => true,//页面刷新自动更新验证码
),
);
}
结束!