Render Partial from Index View

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!

Okay, not sure if this is the best way to do it.

But for all those interested. I ended up changing my review view and nested the _form view into the "View" of that instead of the ReviewComment index view.

Code is below:




<?php $this->widget('zii.widgets.CDetailView', array(

	'data'=>$model,

	'attributes'=>array(

		'id',

		'parent_id',

		'content',

		'status',

		'rating',

		'create_user_id',

		'create_time',

		'update_user_id',

		'update_time',

	),

)); ?>


<div id="comments">

	<?php if($model->commentCount>=1): ?>

	<h3>

		<?php echo $model->commentCount>1 ? $model->commentCount . ' comments' : 'One Comment';?>

	</h3>

	

	<?php $this->renderPartial('_comments',array('comments'=>$model->comment,));?>

	

	<?php endif;?>

	

	<h3>Leave A Comment</h3>

	

	<?php if(Yii::app()->user->hasFlash('commentSubmitted')): ?>

		<div class="flash-success">

			<?php echo Yii::app()->user->getFlash('commentSubmitted');?>

		</div>

	<?php else: ?>

		<?php $this->renderPartial('/reviewComment/_form', array('model'=>$comment,));?>

	<?php endif;?>

</div>