我的验证码没有改变,总是出现相同的单词,除非点击Reload Captcha
按钮。为什么testLimit
不能正常工作?
控制器.php
public $attempts = 5; // allowed 5 attempts
public $counter;
public function actions()
{
return array(
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xf5f5f5,
'testLimit'=>1,
);
}
private function captchaRequired()
{
return Yii::app()->session->itemAt('captchaRequired') >= $this->attempts;
}
public function actionLogin()
{
if (!Yii::app()->user->isGuest) $this->redirect(array('users/update'));
$model = $this->captchaRequired()? new LoginForm('captchaRequired') : new LoginForm;
// collect user input data
if(isset($_POST['LoginForm']))
{
$model->attributes=$_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if($model->validate() && $model->login()) {
$this->redirect(array('users/update'));
} else {
$this->counter = Yii::app()->session->itemAt('captchaRequired') + 1;
Yii::app()->session->add('captchaRequired',$this->counter);
}
}
// display the login form
$this->render('login',array('model'=>$model));
}
查看.php
<?php if($model->scenario == 'captchaRequired'): ?>
<br>
<legend><?php echo CHtml::activeLabelEx($model,'verifyCode'); ?></legend>
<div class="control-group">
<div class="controls">
<?php $this->widget('CCaptcha'); ?>
<?php echo CHtml::activeTextField($model,'verifyCode'); ?>
</div>
</div>
<?php endif; ?>