Displaying image in a CGridView column.

You are viewing revision #4 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version or see the changes made in this revision.

« previous (#3)next (#5) »

This is a simple example of how we can display images in CGridviews.Imagine that you have an image field in your table ie either a location field or a blob type field used to store the images.

$assetsDir = dirname(__FILE__).'/../assets'; /*Assume that you have a folder named assets inside the protected folder used to store the images */

<?php $this->widget('bootstrap.widgets.CGridView', array(
    'type'=>'striped bordered condensed',
			'value'=>'(!empty($data->image))?CHtml::image(Yii::app()->assetManager->publish('.$assetsDir.'$data->image),"",array("style"=>"width:25px;height:25px;")):"no image"',
			'template' => '{update} {delete}',
			'buttons' => array(
				'update' => array(
					'label'=> 'Update',
						'class'=>'btn btn-small update'
				'delete' => array(
					'label'=> 'Delete',
						'class'=>'btn btn-small delete'
            'htmlOptions'=>array('style'=>'width: 80px'),
)); ?>

-Sirin k

Hire Yii developer

9 1
Viewed: 74 851 times
Version: Unknown (update)
Category: How-tos
Written by: sirin k
Last updated by: Maurizio Domba Cerin
Created on: May 15, 2012
Last updated: 7 years ago
Update Article


View all history

Related Articles