Cgridview Columns Property Passed From Action


I’m working on a CGridView widget populated by CArrayDataProvider,

in my case the columns of the grid depend on the SQL query result ( the SQL Query it self is build throw a looping function );

so i have to pass columns array property from the action in the controller,

in controller :

$columns = array();

$columns[] = 'lid';

$formFields = FormFields::model()->findAll();

$sqlString = "SELECT AS lid";

foreach ($formFields as $field){

   $sqlString .=", SQL CODE";

   $columns[] = array('name'=>$field->field_name_key,'header'=>$field->name);


$sqlString .= " FROM table l";

//$columns[]= array('class'=>'CButtonColumn');


$dataProvider=new CArrayDataProvider($rawData, array(















in view :

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






every thig work until now, but when i whoul like to add CButtonColumn to $column array it dosen’t work any more

any idea to fix this problem

Why it’s not working? You got an error message? Something does not behave as expected? If you want help please provide more details.

Do you add the CButtonColumn only to the array passed to the widget?

Hi Hitman911,

I think that CButtonColumn assumes that the key field is ‘id’ when it constructs the urls for the buttons.

So you may have to specify ‘viewButtonUrl’, ‘updateButtonUrl’ and ‘deleteButtonUrl’ properties manually. Or, I believe you can change the key field name from ‘lid’ to ‘id’.

in the controller code i just uncomment this line

//$columns[]= array('class'=>'CButtonColumn');

and i have this error

Trying to get property of non-object

…\framework\base\CComponent.php(612) : eval()'d code(1)


i changed the lid by id but it does’t work :(

Hmm, does CButtonColumn support only AR objects? I’m not sure.

Try specifying the url expressions manually, please.

i used this code

$columns[] = array('type'=>'html','value'=>'CHtml::link("view",Yii::app()->createUrl("lead/view", array("id"=>@$data->id)))');

i had this url lead/view&id=

how can i pass the id to the url ?

i kept my code but just modifing the colomn code from

$columns[]= array('class'=>'CButtonColumn');


$buttons = array(




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




$columns[]= $buttons

Still not work, but i found the problem :)

when i replace $data->id by 2 it work !!!

so the probleme it’s how to get the id from CArrayDataProvider

finally worked , just replaced $data->id by $data[‘id’]