0

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

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; ?>

主文件

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

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

谢谢!

4

1 回答 1

0

这个错误意味着,你试图从任何 yii 组件调用不存在的方法。

你有$this->refresh();你的contact小部件。我猜你想要$model->refresh(),但这只是方法 from CActiveRecord,而不是 from CFormModel。只需删除线,$this->refresh();它应该没问题。

于 2013-06-20T21:16:56.300 回答