Add Function Inside Zii.widgets.grid.cgridview Using $Data As Parameter

Hi,

I am trying to use a function that i added to the controller inside the admin.php

This is the code




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

	'id'=>'articles-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		'DocType',

                array(

                  'type' => 'image',

                  'value' => $this->getArticleImage($data->PageImage),

                ),

		array(

			'class'=>'CButtonColumn',

		),

	),

)); 



getArticlesImages works perfect at the view php but here I don’t know if it is possible to use it…

In the getArticleImage i am using some information of the field PageImage to recreate the correct external path,

Any Ideas?

Thanks a lot

move the method to your model and you can just change it like so


'columns'=>array(

                'DocType',

                array(

                  'type' => 'image',

                  'name' => 'articleImage', // YII is friggin awesome

                ),

                array(

                        'class'=>'CButtonColumn',

                ),

        ),

I am using the flowing and works perfect:

first create a View Helper:

In my case the model is call Articles so i put ArticleViewHelper.php at /protected/components/ArticleViewHelper.php with this code:




<?php

class ArticleViewHelper {

    public static function getArticleImage($image) 

    {

        $amazon = "myurl here/";

        $folder = substr($image, 0, 9) . '/' . substr($image, 10, <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' /> . '/' . substr($image, 19, 2) . '/images/int-';

        return $amazon . $folder . $image;

    }   

}




Then call it from the column definition at the admin.php:




        array(

            'type' => 'image',

            'value' => 'ArticleViewHelper::getArticleImage($data->PageImage)',

            'htmlOptions'=>array('width'=>'300px'),

        ),



And works beautifully

:)

good for you