CButton column evaluateEapression

i have in my admin view and order button column i made using the following code:








 'order'=>array(

                                            'label'=>'Order',     //Text label of the button.

                                            'url'=>'$data->id',       //A PHP expression for generating the URL of the button.

                                            'imageUrl'=>Yii::app()->request->baseUrl.'/images/to_cart.jpg',  //Image URL of the button.

                                            'options'=>array('title'=>'Add to cart','class'=>'toCart','id'=>'$data->id'), //HTML options for the button tag.

                                            //'click'=>'alert("clicked to order");',     //A JS function to be invoked when the button is clicked.

                                            'visible'=>'Yii::app()->user->checkAccess("stock.order")',   //A PHP expression for determining whether the button is visible.

                                           ),



The problem is that in the ‘options’ array ‘id’=>’$data->id’ is not being evaluated, it is just preinted as is, i.e the html produced thereof is … id=’$data->id’, i realised the problem might be in zii.widgets.grid.CButtonColumn on function ‘renderButton’. I added the following lines to make it work:

$options[‘id’]=isset($options[‘id’]) ? $this->evaluateExpression($options[‘id’],array(‘data’=>$data,‘row’=>$row)) : ‘’;

Correct me if im wrong because i would appreciate another way of doing this without changing core framework files.

You can extend CButtonColumn instead of modifying it:




class MyButtonColumn extends CButtonColumn

{

	protected function renderButton($id, $button, $row, $data)

	{

		if (isset($button['options']['id'])) {

			$button['options']['id'] = $this->evaluateExpression($button['options']['id'], array('data' => $data, 'row' => $row));

		}

		parent::renderButton($id, $button, $row, $data);

	}

}



Then use your extended class in CGridView:




'columns' => array(

	//...

	array(

		'class' => 'MyButtonColumn',

		//...

	),

),



Thanx phtamas, that is certainly a better way to do it, i am having the same problem trying to set unique ids for the data cells (<td id=’$data->id’></td>) in cgridview, i will try and implement the same solution.