Display Parent With Children On The Same View

Ok, I’m a .NET guy who’s new to Yii, and I’m getting a bit frustrated with things not working like how I would expect, and not being able to find any examples anywhere the show how to do something this seemingly simple. All I want to do is select a “job” from a list, and on the details view, show a list of “comments” related to that job below the job details.

Here’s what I’ve got in my controller:


	

public function actionView($id)

{

	$job = $this->loadModel($id);

	$comments = $job->jobComments;

                  

	$this->render('view',array(

		'job'=>$job,

		'comments'=>$comments

		));

}



Here’s my view:




<h1>View Job #<?php echo $job->ID; ?></h1>


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

	'data'=>$job,

	'attributes'=>array(

		'ID',

	),

)); ?>


<?php 

    $this->widget('zii.widgets.grid.CGridView', array(

    'dataProvider'=>$comments,

    'columns' => array(

        'ID',

        array(

            'class' => 'CButtonColumn',

        ),

    ),

));

?>



When I add the gridview, the form just stops working. Any assistance in how to get this to work, or links to samples that have this working would be fantastic. I’ve been searching all afternoon to no avail and I’m about at my wits end.

if you have relations defined in ur model rules then simply try this


public function actionView($id)

{

        $job = $this->loadModel($id);

        //$comments = $job->jobComments; 

                  

        $this->render('view',array(

                'job'=>$job,

                //'comments'=>$comments

                ));

}

for cgridview


 $this->widget('zii.widgets.grid.CGridView', array(

    'dataProvider'=>$job->search(), //search method returns a dataProvider for cgridview

    'columns' => array(

        'relation_name.id',

        array(

            'class' => 'CButtonColumn',

        ),

    ),

));