0

我有一个选项卡在视图中,我想在一个选项卡中通过小部件调用显示表单。

<div class="tabcontent" id="country2"> <div class="No-Time">No Reviews ! <?php $this->widget('Review');?> </div> </div>

为此创建了Review模型。然后我创建了组件

<?php 
class Review extends CWidget
{
public $title='Review';
public $visible=true; 
public function run()
{
    if($this->visible)
    {
        $this->renderContent();
    }
}

protected function renderContent()
{

    $merchant_id = Yii::app()->user->id;
    $model  =  new Review;

    $this->performAjaxValidation($model);
$valid  = $model->validate();

    if(isset($_POST['ajax']) && $_POST['ajax']==='review-form')
    {
            echo CActiveForm::validate($model);
            Yii::app()->end();
    }
    $this->render('Review',array('model'=>$model));
}

protected function performAjaxValidation($model)
{
        if(isset($_POST['ajax']) && $_POST['ajax']==='review-form')
        {
                echo CActiveForm::validate($model);
                Yii::app()->end();
        }
}
}
?>

这是我的组件视图文件:

<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'review-form',
'enableAjaxValidation'=>false,
)); ?>



<div class="row">
    <?php echo $form->labelEx($model,'name'); ?>
    <?php echo $form->textField($model,'name'); ?>
    <?php echo $form->error($model,'name'); ?>
</div>

<div class="row">
    <?php echo $form->labelEx($model,'email'); ?>
    <?php echo $form->textField($model,'email'); ?>
    <?php echo $form->error($model,'email'); ?>
</div>

<div class="row">
    <?php echo $form->labelEx($model,'review'); ?>
    <?php echo $form->textField($model,'review'); ?>
    <?php echo $form->error($model,'review'); ?>
</div>

<div class="row">
    <?php echo $form->labelEx($model,'mobile'); ?>
    <?php echo $form->textField($model,'mobile'); ?>
    <?php echo $form->error($model,'mobile'); ?>
</div>

<div class="row">
    <?php echo $form->labelEx($model,'status'); ?>
    <?php echo $form->textField($model,'status'); ?>
    <?php echo $form->error($model,'status'); ?>
</div>

<div class="row">
    <?php echo $form->labelEx($model,'website'); ?>
    <?php echo $form->textField($model,'website'); ?>
    <?php echo $form->error($model,'website'); ?>
</div>

<div class="row">
    <?php echo $form->labelEx($model,'avtar'); ?>
    <?php echo $form->textField($model,'avtar'); ?>
    <?php echo $form->error($model,'avtar'); ?>
</div>

<div class="row">
    <?php echo $form->labelEx($model,'date'); ?>
    <?php echo $form->textField($model,'date'); ?>
    <?php echo $form->error($model,'date'); ?>
</div>


<div class="row buttons">
    <?php echo CHtml::submitButton('Submit'); ?>
</div>
<input type="hidden" name="merchant" id="merchant-id" />
<?php $this->endWidget(); ?>

</div>

返回此错误。不知道为什么会这样。

 Review and its behaviors do not have a method or closure named "isAttributeRequired". 
4

1 回答 1

2

您需要将组件重命名为Review. 错误是因为该行$model= new Review创建了 Review 组件的实例,而不是 Review 模型。

于 2013-04-02T07:22:03.150 回答