I use this grid to view a table with data:
View part:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'news-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'name'=>'enable',
'type'=>'html',
'value'=>'$data->stateHtmlIcon',
),
),
)); ?>
In my model:
public function getStateHtmlIcon() {
if ($this->enable == AbstractModel::ENABLE) {
return '<font class="icon-enable"></font>';
} else {
return '<font class="icon-disable"></font>';
}
}
It doesn’t work, the render stop when display column with stateHtmlIcon.
When I comment ‘type’=>’html’ in the grid (view part), it works but in the column the html is not rendered correctly
<font class="icon-enable"></font>
instead of icon displayed with css style.
So I think I don’t use correctly ‘type’=>’html?
I recently used
which does the job.
See also
http://www.yiiframework.com/doc/api/1.1/CDataColumn#type-detail
http://www.yiiframework.com/doc/api/1.1/CFormatter