0

キャプチャを 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', array('captchaAction'=>'comment/captcha')); ?>
            <?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; ?>

この配列をコメント コントローラーの accessRules() に追加しました。

            array('allow',  // allow all users to perform 'index' and 'view' actions
                    'actions'=>array('index','view', 'captcha'),
                    '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;

コメントフォームはブログの actionView() から表示されるため、問題があると思います。キャプチャは表示されますが、検証されません。何か案は?

4

1 に答える 1

0

また、次のように、captchaAction を Comment モデルの検証ルールに追加する必要があります。

array('verifyCode', 'captcha', 'on' => 'insert', 'allowEmpty'=>!Yii::app()->user->isGuest, 'captchaAction'=>'comment/captcha')
于 2013-01-06T11:53:53.120 に答える