我已经在这里应用了所有其他关于损坏 yii 验证码的解决方案,但无济于事。所以我要添加我自己的问题。
我已经阅读了 yii 博客教程(http://www.yiiframework.com/doc/blog/),但我不想让评论获得批准,我想在评论表单中有一个验证码。我已将此添加到评论表单视图中:
<?php if(CCaptcha::checkRequirements()): ?>
<div class="row">
<?php echo $form->labelEx($model,'verifyCode'); ?>
<div>
<?php $this->widget('CCaptcha'); ?>
<?php echo $form->textField($model,'verifyCode'); ?>
</div>
<div class="hint">Please enter the letters as they are shown in the image above.
<br/>Letters are not case-sensitive.</div>
<?php echo $form->error($model,'verifyCode'); ?>
</div>
<?php endif; ?>
在 CommentController 中,accessRules() 变为:
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view', 'captcha'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'users'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
我在 CommentController 中覆盖了 actions():
public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xD99D25,
),
);
}
在 Comment 模型中,我添加了一条新规则:
array('verifyCode', 'captcha', 'on' => 'insert', 'allowEmpty'=>!Yii::app()->user->isGuest)
和新的公众成员:
public $verifyCode;
联系表格上的验证码工作正常。但是在评论表单中,图像已损坏,并且刷新它的链接不起作用。有任何想法吗?