i followed this because i needed to make a cgridview from some json:
http://www.yiiframework.com/wiki/232/using-filters-with-cgridview-and-carraydataprovider/
its working fine without the custom buttons CButtonColumn but i need them, when i enable them i got this Trying to get property of non-object error.
this is my controller code:
public function actionIndex()
{
$filtersForm=new FiltersForm;
if (isset($_GET['FiltersForm']))
$filtersForm->filters=$_GET['FiltersForm'];
//some info that i will get with an api...
$come_from_server = Array(
Array(
'ref_producto' => 'EF2322',
'nombre_producto' => 'arenilla seca',
'fecha_venta' => '02-09-2013'
),
Array(
'ref_producto' => 'EF2324',
'nombre_producto' => 'arenilla seca adad',
'fecha_venta' => '02-06-2013'
),
Array(
'ref_producto' => 'EF2322',
'nombre_producto' => 'arenilla seca',
'fecha_venta' => '02-06-2013'
),
Array(
'ref_producto' => 'EF2328',
'nombre_producto' => 'otra cosa dsfds',
'fecha_venta' => '02-06-2013'
)
);
$filteredData=$filtersForm->filter($come_from_server);
$dp=new CArrayDataProvider($filteredData, array(
'keyField'=>false,
//'id'=>'ref_producto',
'pagination'=>array(
'pageSize'=>30,
),
));
$this->render('index',
array(
'dataProvider'=>$dp,
'filtersForm'=>$filtersForm,
)
);
}
and in the view:
<?php $this->widget(‘zii.widgets.grid.CGridView’, array(
'dataProvider'=>$dataProvider,
'template'=>"{items}",
'htmlOptions'=>array(
'style'=>'margin:8px;'
),
'filter'=>$filtersForm,
'columns'=>array(
array(
'header'=>'Referencia Producto',
'type'=>'raw',
'value'=>'CHtml::encode($data["ref_producto"])',
'htmlOptions'=>array(
'style'=>'width:50px;'
)
),
array(
'header'=>'Nombre Producto',
'value'=>'$data["nombre_producto"]'
), /*********************************IF I COMMENT THIS BELOW IT WORKS BUT I NEED THIS *******************/
array(
'class'=>'CButtonColumn',
'header'=>'Accion',
'template'=>'{view}{download}{viewpdf}{printpdf}',
'buttons'=> array(
'download'=>array(
'label'=>'Bajar',
'imageUrl'=>false,
'icon'=>'icon-download',
'url'=>'http://www.google.com', // example url just to test
),
'viewpdf'=>array(
'label'=>'Ver pdf',
'icon'=>'icon-file',
'url'=>'http://www.google.com',
),
'printpdf'=>array(
'label'=>'Imprimir pdf',
'icon'=>'icon-print',
'url'=>'http://www.google.com',
'options'=>array(
'class' => 'print',
),
),
),
), /******** HERE END ****************/
),
));
?>
more of the error code:
HP notice
Trying to get property of non-object
/home/raowl/public_html/yii/framework/base/CComponent.php(612) : eval()'d code(1)