Cgridview, Carraydataprovider And Columns

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?

Hi,

I hope this is the only way it can help you.

<?php

$this->widget(‘zii.widgets.grid.CGridView’, array(

'dataProvider' =&gt; &#036;model-&gt;search(),


'filter' =&gt; &#036;model,


'columns' =&gt; array(


    array(


        'name'=&gt;'version',


        'header'=&gt;&#036;model-&gt;getAttributeLabel('version'),


    ),


    array(


        'name'=&gt;'description',


        'header'=&gt;&#036;model-&gt;getAttributeLabel('description'),


    ),


),


'selectableRows' =&gt; 0,


'htmlOptions' =&gt; array('style' =&gt; 'width:700px'),

));

?>

Thanks

chandran nepolean