Yii:: CGridView – show relations HAS_MANY in gridview

Posted: May 15, 2014 in Php, Yii Framework
Tags: ,

 

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',
 ),
Comments
  1. […] : https://hafiznor.wordpress.com/2014/05/15/yii-cgridview-show-relations-has_many-in-gridview/ Make sure you have the relations […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s