我正在使用 portlet 来显示联系表格 - 与作为标准生成的静态页面上的完全相同。我正在使用相同的 ContactForm 模型。表单显示但验证码未显示并报告“CCaptchaValidator.action“验证码”无效。无法在当前控制器中找到这样的操作。”
我是 yii 的新手,所以要花很多时间才能弄清楚所有事情。有什么快速建议我会做些什么来让它工作吗?
最好的!
Yii::import('zii.widgets.CPortlet');
class ContactFormCard extends CPortlet
{
    public $title='Contact';
protected function renderContent()
{
    $model=new ContactForm;
    if(isset($_POST['ContactForm']))
    {
        $model->attributes=$_POST['ContactForm'];
        if($model->validate())
            $this->controller->refresh();
    }
    $this->render('contactFormCard',array('model'=>$model));
}
public function actions()
{
    return array(
        'captcha'=>array(
            'class'=>'CCaptchaAction',
            'backColor'=>0xFFFFFF,
        ),
    );
}
}
在 portlet 视图中:
<?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; ?>