Thursday, 18 December 2014

MANY relation handling in YII

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 = '<div class="edata">';
 foreach ($objData as $obj) {
      $tmp = $tmp . $obj->name . '<br/>'; 
 }
 $tmp = $tmp.'</div>';
 return $tmp;
}
In your GridView columns:
array(
 'header' => 'PEOPLE',
 'value' => 'HumanModel::extractObjData($data->example)',
 'type' => 'raw',
 ),

No comments:

Post a Comment