Quantcast
Channel: Live News for Yii Framework
Viewing all articles
Browse latest Browse all 3361

[Wiki] Display image on CGridView column and open a fancy-box

$
0
0

First write your code on admin.php file

$height='30px';
 $width='30px';
array(
 
        'name'=>'image',
        'type'=>'html',
        //'value'=>'CHtml::image(Yii::app()->assetManager->publish('.$assetsDir.'$model->image),"",array("style"=>"width:25px;height:25px;"))',
        //'value' => 'CHtml::tag("img", array("src" => $model->image ? "340-Koala.jpg" : "340-Koala.jpg"), "")'   
       'value'=>'(!empty($data["image"])) ? CHtml::link(CHtml::tag("img",array("height"=>\''.$height.'\',\'width\'=>\''.$width.'\',"src" => UtilityHtml::getImageCoupon(GxHtml::valueEx($data,\'image\')))),"",array("class"=>"fancybox1","href"=> UtilityHtml::getImageCoupon(GxHtml::valueEx($data,\'image\')))) :  CHtml::tag("img",array("height"=>\''.$height.'\',\'width\'=>\''.$width.'\',"src" => UtilityHtml::getImageCoupon(GxHtml::valueEx($data,\'image\'))))',
        ),

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

public static function getImageCoupon($image)
    {
        if($image!='' && file_exists(YiiBase::getPathOfAlias('webroot').'/upload/coupon/'.$image)){
            return Yii::app()->request->baseUrl.'/upload/coupon/'.$image;
        }else {
 
            return Yii::app()->request->baseUrl.'/upload/coupon/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...


Viewing all articles
Browse latest Browse all 3361

Trending Articles