我的验证码不工作与博客


Yii captcha not working with blog

我已经在这里应用了所有其他解决方案,但无济于事。所以我加入了我自己的问题。

我已经通过了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)

和new public member:

public $verifyCode;

联系表单上的验证码工作正常。但是在评论表单中,图像是坏的,刷新它的链接不起作用。什么好主意吗?

我将这段代码添加到博客演示中,看起来captcha的请求将转到PostController而不是CommentController。如果您将captcha动作添加到PostController,它应该可以工作。

是否打开了firebug或web检查器?它对captcha请求的响应是什么?