Hi there,
I wonder what would be the best way to show complex data in a cgridview. For example I’ve got users who tag images in an application. On the user admin listings I’d like to show the following information.
UserName | email | Top10Tags | …
Peter | peter@dummyllc.com | Cat (5), Dogs (3), House(2), … | …
At the moment I created a method in my User model
public function getTopTags($num_tags=10) {
$tags = Yii::app()->db->createCommand()
// ...
// retrieve data from database and parse it to string
// ...
return $string_of_tags
}
Which I embedd in the cgridview like that
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id' => 'users-grid',
...
'columns' => array(
'id',
'username',
'email',
array(
'header' => Yii::t('app', 'Top Tags'),
'type' => 'html',
'value'=>'$data->getTopTags()',
),
...
While this works fine I wonder if there is a better way to do such things. I’m particularly worried about performance. As every row in the grid creates another hit in the database. Is there a better way to render the results of subselects in a gridview?
many thanks!