Cgridview In Parentview

Hello

Yii 1.1.14

I have an employee table and a comment table

In the employee view i want to show all the comments of the employee in a grid (after the employee fields)

I tried to follow the example here

Here is where I am :

New code to defining a new search function in the model :




public $commentdate_param;

public $commentobservation_param;

...

public function rules()

{

    return array(

        ...

        array('public $commentdate_param, commentobservation_param, ...', 'safe', 'on'=>'search, searchIncludingComments'),

);

public function relations()

{

    return array(

        ...

        'employeecomments' => array(self::HAS_MANY, 'Employeecomments', 'employee_id'),

    );

}


public function searchIncludingComments($parentID)

    {

        $criteria=new CDbCriteria;

        $criteria->with=array('employeecomments');

        $criteria->together = true;

        $criteria->compare('t.employee_id',$parentID,false); 

        $criteria->compare('employeecomments.date', $this->commentdate_param,true);

        $criteria->compare('employeecomments.observation', $this->commentobservation_param,true);

		

        $sort = new CSort;

        $sort->attributes = array(

            'commentdate_param' => array(

            'asc' => 'date_desc',

            'desc' => 'date_desc DESC',

            ), '*', /* Treat all other columns normally */

        );

 

        return new CActiveDataProvider($this, array(

            'criteria'=>$criteria,

            'sort'=>$sort,

        ));

    }



Adding code in the controller actionView :




...

$child_model = new Employee("searchIncludingComments");

$child_model->unsetAttributes();

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

    'model'=>$this->loadModel($id),

    'child_model'=>$child_model,

    'parentID' => $id

));



Adding code in the view :




...

<h3>Comments</h3>

<?php

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

    'id'=>'child-grid',

    'dataProvider'=>$child_model->searchIncludingComments($parentID),

    'filter'=>$child_model,

    'columns'=>array(

        'date',

        'observation',

        array(

            'class'=>'CButtonColumn',

        ),

    ),

));

...



But I must have missed something because when it comes to grid rendering stops - but no error in log

Would be nice if somebody could help me !

I found the solution for me - all my changes and controler are worthless because now I do all stuff in the view :




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

			'id'=>'comments-grid',

			'dataProvider'=>new CActiveDataProvider('Employeecomment',array(

				'criteria'=>array(

					'condition'=>'employee_id=:eid',

					'params'=>array(':eid'=>$model->id),

				),

				'sort'=>array(

					'defaultOrder'=>'date DESC',

				),

			)),



Sure there is something I did not understand why it did not work …

"public $commentdate_param," says you have a filed called public, and $ is not allowed in rules.

BTW: This sounds like comments for a post in the Blog demo.