Yii:: CGridView – show relations HAS_MANY in gridview

 

Make sure you have the relations object:

public function relations()
 {
    return array(
         'example' => array(self::HAS_MANY, 'exTask', 'ex_id'),
   );
 }

 

Add function in your model file:

public static function extractObjData($objData) {
 $tmp = '
'; foreach ($objData as $obj) { $tmp = $tmp . $obj->name . '
'; }
 $tmp = $tmp.'
'; return $tmp; }

In your GridView columns:

array(
 'header' => 'PEOPLE',
 'value' => 'HumanModel::extractObjData($data->example)',
 'type' => 'raw',
 ),
Advertisements