YII 验证码

验证码类

<?php

class Captcha extends CCaptchaAction
{
    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())),
            ));
        } else{
            $this->renderImage($this->getVerifyCode(true)); //刷新页面时会调用这个,问题就出现在这,他调用
        }
        Yii::app()->end();
    }
}

 controller

public function actions()
{
    return array(
        // captcha action renders the CAPTCHA image displayed on the contact page
        'captcha'=>array(
            'class'=>'Captcha',
            'maxLength'=>4,
            'minLength'=>4,
            'width' => 100
        ),
    );
}

 html

<?php $this->widget('CCaptcha', array('showRefreshButton' => false, 'clickableImage' => true, 'imageOptions' => array('title' => '点击换图', 'style' => 'cursor:pointer;width: 110px; height: 35px;'))); ?>                       
 

猜你喜欢

转载自hudeyong926.iteye.com/blog/2173817
yii