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(



)); ?>

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



)); ?>

	<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 class="row buttons">

		<?php echo CHtml::submitButton($model->isNewRecord ? 'Submit' : 'Save'); ?>


	<?php if(!$model->isNewRecord):?>

		<?php if($model->status==ReviewComment::STATUS_PENDING): ?>

			<span class="pending">Pending approval</span> |

			<?php echo CHtml::linkButton('Approve', array(


			)); ?>

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













)); ?>

<div id="comments">

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


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



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


	<?php else: ?>

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

	<?php endif;?>