Dynamic Label In Cgridview


How can i show cgridview ‘label’ property by a php variable? for example

‘contract1’ => array




                            'url'=>'Yii::app()->createUrl("contract/bonus", array("id"=>$data->id))',

                            'visible'=>'($data["wish_user"]["wish_user_profile"]["profilecampaign"]["reward"] != "")?$data["wish_user"]["wish_user_profile"]["profilecampaign"]["reward"]:""',


thanks in advance

Hi prashant.tyagi

check the below code instead of ‘label’=>$yourphpvalue,


        'label' => $yourphpvalue,

        'value' => $yourphpvalue2,

        'type' => 'raw',


You can use the labelExpression property, assuming that you’re using the CLinkColumn class.

thanks KonApaz and Keith For yout replay.the code has actually uses CButtonColumn class.can you tell me how can i do this with CButtonColumn class? tahnks


                   'class' => 'CButtonColumn',

                    'buttons' => array(


														'add' => array(

                                                        'label' => Yii::t('Exam','Manage This Exam'), // text label of the button


                                                        'url'=>'Yii::app()->createUrl("/courses/exams/create", array("exam_group_id"=>$data->id,"id"=>$_REQUEST["id"]))', // a PHP expression for generating the URL of the button




                   'template' => '{add}',





thanks Rajith for your replay

now i have a different problem, can i use ‘visible’ property with ‘CLinkColoumn’ class.thanks

Try this



‘htmlOptions’=>array(‘class’=>‘my-no-display’), //with css .my-no-display{display:none}




i mean ‘visible’ is not working in this code


            'class' => 'CLinkColumn',

            'labelExpression'=> '"| $".$data["wish_user"]["wish_user_profile"]["profilecampaign"]["reward"]." Reward"',

            'urlExpression'=>'Yii::app()->createUrl("contract/bonus", array("id"=>$data->id))',

           'visible'=>'(trim($data["wish_user"]["wish_user_profile"]["specialUser"]) != "") && (trim($data["wish_user"]["wish_user_profile"]["profilecampaign"]["reward"]) != "") && ($data->wish_contract["contract_status"] ==0) && ($data->status ==0) && ((strtotime("today")-strtotime(date("d-m-Y", $data->created)))/86400)>3',


                    'class'=> 'leadClass2',


Check your conditions partially

(trim($data[“wish_user”][“wish_user_profile”][“specialUser”]) != “”) && (trim($data[“wish_user”][“wish_user_profile”][“profilecampaign”][“reward”]) != “”) && ($data->wish_contract[“contract_status”] ==0) && ($data->status ==0) && ((strtotime(“today”)-strtotime(date(“d-m-Y”, $data->created)))/86400)>3’

test it by line disabled the others each time, may your logic cindition or field is invalid

sorry for asking question again and again

my problem is existing code uses CButtonColumn to show default actions.now i have to show label of one action by some database value with some conditions.can somebody tell me how can i set label to a database value?.i had add a CLinkColoumn ACTION and its label expression property works well but visible property not works well. can somebody tell me how to use visible property with CLinkColoumn class? or somebody can explain Ranjith’s example?.thanks

what u actually want? CButtonColumn? or CLinkColoumn ? u can set any values to the label, as u wish…

i want to use CButtonColumn as it is already applies to existing action.now how can i set ‘label’ of action a php variable as ‘label’ property of CButtonColumn doesn’t allow php variable for ‘label’