Yii 1.1: image-column

a Column for CGridView that can display a image, with a optional link

This column assumes that the filename is saved as a path to the image that is to be rendered. If no pathPrefix is given, it assumes Yii::app()->baseUrl as a prefix for the image.


extract the file to your application components/ directory.

Example Usage

  $this->widget('zii.widgets.grid.CGridView', array(
            'name' => 'filename',
            'htmlOptions' => array('style' => 'width: 150px;'),
)); ?>

Total 4 comments

#8108 report it
cecilio at 2012/05/10 01:27pm
Change on 'name' attribute


I've changed renderDataCellContent function, to support names with relations, like 'name'=>'Post.Author'

//$image = CHtml::image($this->pathPrefix . $data->{$this->name} . $this->pathSuffix,
        $image = CHtml::image($this->pathPrefix . CHtml::value($data,$this->name) . $this->pathSuffix,
#4046 report it
pcs2112 at 2011/05/31 05:46pm

nice job

#3937 report it
thyseus at 2011/05/23 04:14am
samdark´ s implementation

Nice. Would i have found your ImageColumn, i would had used yours rather than doing a own. Your 'imagePathExpression' idea may be better than mine, it allows for more flexible path constructions ;)

#3927 report it
samdark at 2011/05/22 02:03pm
Another implementation

I've created another implementation a while ago.

Leave a comment

Please to leave your comment.

Create extension