PHP Code in CGridView

Hi to all…

I need to execute some PHP code for each iteration with CGridView. For example, I need to generate some image thumbnails when CGridView renders each row. Can you please let me know how can I do that???

Thanks

extend CGridColumn to render your image

http://blog.mbischof.de/cgridcolumn

Thanks MBI for your response. I have my ImageColumn.php class file in protected/components/ImageColumn.php

It is not working by simply specifying ‘class’ property of CGridColumn. Can you please let me know if I need to include it some where?

Thanks

I got my first issue fixed.

One more thing to ask please.

I need to pass few parameters to my Custom CGridColumn class for example, thumbnail path, width and height. I did it like this:


Yii::import('zii.widgets.grid.CGridColumn');


class ImageColumn extends CGridColumn {


	public $file;

	public $width;

	public $height;

	

	

	public function renderDataCellContent($row, $data) {

	

        $this->file = $data->{$this->file};

        $this->width = $data->{$this->width};

        $this->height = $data->{$this->height};

        

		

        $thumb = Yii::app()->thumb;

        $thumb->file = $this->file;

        $thumb->width = $this->width;

        $thumb->height = $this->height;

        

        

        $thumb->make();

        

        $ThumbImage = $thumb->save();

        

        echo '<img src="'.Yii::app()->baseURL.$ThumbImage.'" />';

    }

}

Can you please let me know how should I pass these values in CGridView:


array(

	'class'=>'ImageColumn',

	'file'=>Yii::app()->basePath.'../uploads/images/headerThumbs/'.$date->image_hdr,

	'width'=>50,

	'height'=>50

),

Thanks a lot…




Yii::import('zii.widgets.grid.CGridColumn');


class ImageColumn extends CGridColumn

{

    public $width = 50;

    public $height = 50;

        

    public function renderDataCellContent($row, $data)

    {            

        $thumb = Yii::app()->thumb;


        $thumb->file = $data->image_hdr; //dont forget path to image

        $thumb->width = $this->width;

        $thumb->height = $this->height;

        

        $thumb->make();

        $ThumbImage = $thumb->save();

        

        echo '<img src="'.Yii::app()->baseURL . $ThumbImage . '" />';

    }

}






array(

    'class'=>'ImageColumn'

),