联系表单工作但方法或闭包“刷新”给出错误

时间:2013-06-20 21:08:23

标签: php yii widget refresh contact

我通过改编标准联系表格为联系表单制作了一个小部件,效果很好。电子邮件会被发送,但在刷新时我会收到错误:

contact and its behaviors do not have a method or closure named "refresh".

当我翻页时,错误消失,并显示“我们将与您取得联系”的消息。我一直在打破我的头脑,我可能看错了方向,但找不到原因......

型号:

    class ContactForm extends CFormModel
{
    public $gender;
    public $name;
    public $lastname;
    public $email;
    //public $subject;
    //public $body;
    //public $verifyCode;

    /**
     * Declares the validation rules.
     */
    public function rules()
    {
        return array(
            // name, email, subject and body are required
            array('name, lastname, email, gender', 'required'),
            // email has to be a valid email address
            array('email', 'email'),
            // verifyCode needs to be entered correctly
            //array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
        );
    }

    /**
     * Declares customized attribute labels.
     * If not declared here, an attribute would have a label that is
     * the same as its name with the first letter in upper case.
     */
    public function attributeLabels()
    {
        return array(
            'verifyCode'=>'Verification Code',
        );
    }
}

组件:

   class contact extends CWidget
{
    public function run()
    {
        $model=new ContactForm;
        if(isset($_POST['ContactForm']))
        {
            $model->attributes=$_POST['ContactForm'];
            if($model->validate())
            {
                $name='=?UTF-8?B?'.base64_encode($model->name).'?=';
                $subject='Contact Kumbia Website '.$model->name.' '.$model->lastname;
                $headers="From: $name $lastname <{$model->email}>\r\n".
                    "Reply-To: {$model->email}\r\n".
                    "MIME-Version: 1.0\r\n".
                    "Content-type: text/plain; charset=UTF-8";
                $body='Deze persoon wil graag contact met ons!! ('.$model->gender.') Email: '.$model->email.' Abrazo Team Website...';

                mail(Yii::app()->params['adminEmail'],$subject,$body,$headers);
                Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
                $this->refresh();
            }
        }
        $this->render('_contact',array('model'=>$model));
    }
}

组件视图:

    <div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'contact-form',
    'enableClientValidation'=>true,
    'clientOptions'=>array(
        'validateOnSubmit'=>true,
    ),
)); ?>

    <div class="lijn"></div>
    <?php //echo $form->errorSummary($model); ?>

    <table>
        <tr>
            <td>

            </td>
            <td>
                <?php
                    echo $form->radioButtonList($model, 'gender',
                        array(  'Mannetje' => 'MALE',
                                'Vrouwtje' => 'FEMALE' ),
                        array( 'separator' => " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; " ) );
                ?>
                <?php echo $form->error($model,'gender'); ?>
            </td>
            <td>

            </td>
            <td>

            </td>
        <tr>
        <tr>
            <td>
                FIRST NAME
            </td>
            <td style="width:100px;">
                <?php //echo $form->labelEx($model,'name'); ?>
                <?php echo $form->textField($model,'name'); ?>
                <?php echo $form->error($model,'name'); ?>
            </td>
            <td>
                LAST NAME
            </td>
            <td>
                <?php //echo $form->labelEx($model,'lastname'); ?>
                <?php echo $form->textField($model,'lastname'); ?>
                <?php echo $form->error($model,'lastname'); ?>
            </td>
        <tr>
        <tr>
            <td>
                EMAIL ADDRESS
            </td>
            <td>
                <?php //echo $form->labelEx($model,'email'); ?>
                <?php echo $form->textField($model,'email'); ?>
                <?php echo $form->error($model,'email'); ?>
            </td>
            <td>

            </td>
            <td>

            </td>
        <tr>
    </table>

    <div class="lijn2"></div>

    <div class="row buttons">
        <?php echo CHtml::submitButton('Submit'); ?>
    </div>

<?php $this->endWidget(); ?>

</div><!-- form -->

<?php endif; ?>

Main.php

<?php $this->widget('application.components.contact'); ?>

有谁知道我在这里做错了什么?

谢谢!

1 个答案:

答案 0 :(得分:0)

此错误表示您尝试从任何yii组件调用非existend方法。

$this->refresh();窗口小部件中有contact。我想你想要$model->refresh(),但这只是来自CActiveRecord的方法,而不是来自CFormModel的方法。只需删除$this->refresh();行,就可以了。