How to assign label name of cbutton to be $data?

137 Views Asked by At

How can i get $data->user->name to be label name of button.

'label' => $data->user->name

in :

array(
        'class'=>'CButtonColumn',
        'template'=>'{Preview}',
        'buttons'=>array(
            'Preview'=>array(
                'label'=>'Details',
                'url'=>'Yii::app()->createUrl("/administration/order/getBillingInfo", array("id"=>$data->id))',
                'click'=>'window.billingInfo',

            ),
        ),
        'htmlOptions'=>array('style'=>'text-align:center;', 'class'=>'gButtons'),
    ),

This is my Widget:

<?php
$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'orders-grid',
    'ajaxUpdate'=>false,
    'dataProvider'=>$model->search(),
    'htmlOptions'=>array('class'=>'grid'),
    'pager'=>array(
        'maxButtonCount'=>Yii::app()->params['maxButtonCount'],
    ),

How can i get $data->user->name to be label name of button.

3

There are 3 best solutions below

1
MrSoundless On

$data does not exist in that context

Try:

'label' => '$data->user->name'
3
DaSourcerer On

label is supposed to be a fixed string, not an expression. You will have to extend CButtonColumn so it'll feature a labelExpression that gets evaluated. The code for the url property should give you a fairly good idea.

1
Michiel On

Try with double quotes:

'label' => "$data->user->name"