if i pass to CGridView activedataprovider, grid render columns headers using method attributeLabels
but if i use such code
'dataProvider'=>new CArrayDataProvider(::model()->findAll())
grid headers displays database column names
how can i using attributeLabels with CArrayDataProvider?
You can’t, because the array holds only values under keys, it does not contain labels or any reference to the model. You have to set the ‘header’ property of each column definition in your grid.
If your column definition matches some model attributes you could iterate over it and set those properties automatically before passing it to the grid.
how can i fix array from method findAll() to show right headers?
something like
$items=::model()->findAll('bind headers'=>true)
or the only way is manually set headers in grid?
findAll() returns an array of models, which are objects.
Why won’t you use CActiveDataProvider?
kusanagi:
if i pass to CGridView activedataprovider, grid render columns headers using method attributeLabels
but if i use such code
'dataProvider'=>new CArrayDataProvider(::model()->findAll())
grid headers displays database column names
how can i using attributeLabels with CArrayDataProvider?
Hi,
I hope this is the only way it can help you.
<?php
$this->widget(‘zii.widgets.grid.CGridView’, array(
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
array(
'name'=>'version',
'header'=>$model->getAttributeLabel('version'),
),
array(
'name'=>'description',
'header'=>$model->getAttributeLabel('description'),
),
),
'selectableRows' => 0,
'htmlOptions' => array('style' => 'width:700px'),
));
?>
Thanks
chandran nepolean