CGridView not allowing custom title value.

I have an annoying problem with CGridView in that it won’t accept my custom name for the field header. In the example below I am trying to have the column header print ‘Is paid’. However this is causing an exception with the message ‘Is paid’ is not defined. If I change it back to the MySQL column name ‘expensePaid’ it works OK.




 <?php $this->widget('zii.widgets.grid.CGridView', array(

     'id'=>'expense-grid',

     'dataProvider'=>$model->search(),

     'filter'=>$model,

     'columns'=>array(

         'id',

         'creditor.name',

         'expenseName',

         'expenseTotal',

         'expensePaid',

         array('name'=>'Is paid', 'value'=>'Expense::getStatusText($data["expensePaid"])'),

         'expensePaidDate',

         array(

             'class'=>'CButtonColumn',

         ),

     ),

 )); ?>



I have used this is the past and it’s work as expected. Is there cases where this approach will not work?

This is with Yii version 1.1.10.

Hello

See here:

http://www.yiiframework.com/doc/api/1.1/CGridView#columns-detail

and

http://www.yiiframework.com/doc/api/1.1/CDataColumn#name-detail

and

http://www.yiiframework.com/doc/api/1.1/CGridColumn#header-detail

So:


         array('header'=>'Is paid', 'value'=>'Expense::getStatusText($data["expensePaid"])'),

Thanks for the response.

This did work. However I’m confused why is some instances I can use name and other times I have to use header.

As far as I know, you can use ‘name’ in camelCase even if it is not an attribute of the model. However, if that’s the case, you must provide a ‘value’, and you won’t be able to sort by that column, obviously.