With a cActiveDataProvider, I’m able to use ‘value’=>’$data->nameOfTheColumn’ in the grid view, but CSqlDataProvider is requiring me to use it like this: ‘value’=>’$data[“issueCount”]’ (like an array).
Here’s an example:
In Controller:
public function actionIndex()
{
$sql="SELECT site_id, COUNT(*) as issueCount FROM issues2 GROUP BY site_id ORDER BY openCount DESC";
$dataProvider=new CSqlDataProvider($sql, array(
'pagination'=>array(
'pageSize'=>10,
),
'keyField'=>'site_id'
));
$this->render('index',array('dataProvider'=>$dataProvider));
}
In View:
$this->widget('bootstrap.widgets.TbGridView', array(
'id'=>'issues-grid',
'dataProvider'=>$dataProvider,
'template'=>"{items}",
'columns'=>array(
array(
'type'=>'raw',
'htmlOptions' => array('style' => 'width: 50px'),
'header'=>'Total Issues',
'value'=>'$data["issueCount"]',
),
));
The different syntax might confuse people. Why does it need to be different? Maybe we can make CSqlDataProvider treat it like an object?