验证码不适用于yii

时间:2012-01-04 13:05:38

标签: php yii captcha

用户模型:

public function rules()
{
    return array(
        ...
        array('verifyCode', 'captcha', 'on'=>'register'),
        ...
    );
}

UserController中

public function actionRegister()
{
    $model=new User;
    if(isset($_POST['User']))
    {
        $model->attributes=$_POST['User'];
        if($model->save()){
             $this->redirect(array('login'));
        }
    }
    ...
    $this->render('register');
}

查看 - register.php

<?php $this->widget('CCaptcha'); ?>
            <div class="captcha"><?php echo CHtml::activeTextField( $model,'verifyCode', array('class'=>'captcha')); ?></div>
    <?php echo $form->error($model,'verifyCode'); ?>

这会使验证码正常,但验证不会发生。可能是什么问题?