Hello Yiiers,
I’m trying to render a partial view from the index view. I have the following code:
<h1>Blog Comments</h1>
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
)); ?>
<?php if(isset($_GET[pid])) : ?>
<?php echo $this->renderPartial('_form', array('model'=>$dataProvider)); ?>
<?php endif;?>
The _form view (which exists) is throwing an error. From what I can surmise, the error is because I am passing in a CActiveDataProvider and it is looking for a CActiveRecord. The index view and the _form view are both a part of the same controller/model so all data that is available for the index view should be enough for the _form. I don’t know if I am passing the data correctly though.
The _form code is:
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'review-comment-form',
'enableAjaxValidation'=>true,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'content'); ?>
<?php echo $form->textArea($model,'content',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'content'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Submit' : 'Save'); ?>
</div>
<?php if(!$model->isNewRecord):?>
<?php if($model->status==ReviewComment::STATUS_PENDING): ?>
<span class="pending">Pending approval</span> |
<?php echo CHtml::linkButton('Approve', array(
'submit'=>array('approve','id'=>$model->id),
)); ?>
<?php endif;?>
<?php endif;?>
<?php $this->endWidget(); ?>
</div><!-- form -->
And the error occurs on the first reference to $model.
Any help would be much appreciated!