Display image on CGridView column and open a fancy-box

You are viewing revision #3 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.

next (#4) »

First write your code on admin.php file

$height='30px';
 $width='30px';
 $path='/upload/liquor/';
array(
		    'name'=>'liquor_logo',
		    'type'=>'html',
                    'filter' => '',
		    'value'=>'(!empty($data["liquor_logo"])) ? CHtml::link(CHtml::tag("img",array("height"=>\''.$height.'\',\'width\'=>\''.$width.'\',"src" => UtilityHtml::getAdminImage(GxHtml::valueEx($data,\'liquor_logo\'),\''.$path.'\'))),"",array("class"=>"fancybox1","href"=> UtilityHtml::getAdminImage(GxHtml::valueEx($data,\'liquor_logo\'),\''.$path.'\'))) :  CHtml::tag("img",array("height"=>\''.$height.'\',\'width\'=>\''.$width.'\',"src" => UtilityHtml::getAdminImage(GxHtml::valueEx($data,\'liquor_logo\'),\''.$path.'\')))',
                    'htmlOptions' => array('width' => '10%'),   
		),	

create the UtilityHtml.php file on component folder otherwise which common file call you can put the function...getImageCoupon

public static function getAdminImage($image, $path) {

		if ($image != '' && file_exists(YiiBase::getPathOfAlias('webroot') . $path . $image)) {
			return Yii::app()->request->baseUrl . $path . $image;
		} else {
			return Yii::app()->request->baseUrl . $path . 'images.jpg';
		}
	}

and finally open a image on fancybox

<script type="text/javascript">
	$(document).ready(function() {
	    $(".fancybox1").fancybox({
	          helpers: {
	              title : {
	                  type : 'float'
	              }
	          }
	      });
	});
	
</script>

Hope it will be helpful...