Manipulating a dataProvider's data

Hello all,

Is it possible to manipulate the data that’s stored in a dataProvider? I am using the CGridView to display the info. Before displaying the data from the dataProvider in that grid, I need the data to run through PHP’s strip_tags(), to remove any HTML tags:

  1. Retrieve data via CActiveDataProvider

  2. Manipulate data by running strip_tags() on the columns

  3. Output the data using the CGridView widget

I realize I could just output the data manually and not use a dataProvider and grid view, but I really don’t want to complicate things, so I’m wondering if there is a way to somehow manipulate my dataProvider’s data, or tell the CGridView to manipulate the data before outputting it.

Here’s the relevant code:

The controller:


$dataProvider=new CActiveDataProvider('Data', array(

    'criteria'=>array(

        'condition'=>'active=1',

The view:


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

	'dataProvider'=>$dataProvider,

	'columns'=>array(

	   'column1',

	   array(

	       'class'=>'CButtonColumn',

	       'template'=>'{update}{delete}',

	   ),

	),

));

Thanks a lot for any help

You need use $data variable.




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

        'dataProvider'=>$dataProvider,

        'columns'=>array(

           'column1',

           array(

             'name'=>'column2',

             'value'=>'strip_tags($data->column2)'

           ),

           array(

               'class'=>'CButtonColumn',

               'template'=>'{update}{delete}',

           ),

        ),

));



Thank you very much, that works exactly as I need it to. :)

One solution that came into my mind (maybe not the perfect one) would be the following:

For each column, add this array in CGridView config:

[PHP]

array(

'name' => 'column_name',


'value'=>'strip_tags($data->column_name)',

),

[/PHP]

Where column_name needs to be replaced by the real name.

An other solution would be to override CGridColumn::renderDataCellContent().