我在视图中有一个标签,在一个标签中我想通过小组调用显示一个表单。
<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".
答案 0 :(得分:2)
您需要将组件重命名为Review
以外的其他组件。该错误是因为行$model= new Review
创建了Review组件的实例而不是Review模型。