Show Uploaded Image To Cgridview And Table

I have uploaded images into my project folder. But I cannot show it in the:

  1. CGridVIew

4949

cgrid.png

  1. Table

4950

table.png

Can anyone teach me how to do it?? Thanks all

Update your model to get image

public function getImgbanner()

{


	$uploadPath = Yii::app()->params['uploadUrl1']; //folder you upload the image


	$img ="<img src='$uploadPath$this->image1' width=100px />"; //code img html, witdh and height can you offer self, for image file, you can change $this->column name of picture


	return $img;


	


}

And in Cgridview, you can call it in column

array

	(


	'name'=>'imgbanner',


	'type'=>'html', //this is for show html code


	),

[font="Arial"][size="2"]Try this [/size][/font]

[font="Arial"][size="2"] 1) defined in admin grid view file[/size][/font]


height = 30px;


weight = 30px;

2) [font="Arial"][size="2"] In admin grid view [/size][/font]

[font="Arial"][size="2"] array([/size][/font]

[font=“Arial”][size=“2”] ‘name’=>‘image’,[/size][/font]

[font=“Arial”][size=“2”] ‘header’=>‘Image’,[/size][/font]

[font=“Arial”][size=“2”] ‘filter’=>’’,[/size][/font]

[font=“Arial”][size=“2”] ‘type’ => ‘html’,[/size][/font]

[font=“Arial”][size=“2”] ‘value’=> ‘CHtml::tag(“div”, array(“style”=>“text-align: center” ) , CHtml::tag(“img”, array(“height”=>\’’.$height.’\’,\‘width\’=>\’’.$width.’\’,“src” => UtilityHtml::getImageCoupon(GxHtml::valueEx($data,\‘image\’)))))’,[/size][/font]

[font=“Arial”][size=“2”] //‘value’=> ‘UtilityHtml::getImageDisplay(\‘interest\’, $data->image_icon)’,[/size][/font]

[font="Arial"][size="2"] ),[/size][/font]

[font="Arial"][size="2"]

[/size][/font][font="Arial"][size="2"]3) call a function in [/size][/font][font="Arial"][size="2"]UtilityHtml file[/size][/font]

[font="Arial"][size="2"]public static function getImageCoupon($image)[/size][/font]

[font="Arial"][size="2"] {[/size][/font]

[font=“Arial”][size=“2”] if($image!=’’ && file_exists(YiiBase::getPathOfAlias(‘webroot’).’/upload/coupon/’.$image)){[/size][/font]

[font=“Arial”][size=“2”] return Yii::app()->request->baseUrl.’/upload/coupon/’.$image;[/size][/font]

[font="Arial"][size="2"] }else {[/size][/font]

[font=“Arial”] [/font][font=“Arial”][size=“2”] return Yii::app()->request->baseUrl.’/upload/coupon/images.jpg’;[/size][/font]

[font="Arial"][size="2"] }[/size][/font]

[font="Arial"][size="2"] }[/size][/font]

Use this in Gridview… inside the ‘columns’ array…




          array(

		'header'=>'Photo',

              'type' => 'raw',

              'value' => 'CHtml::image(Yii::app()->baseUrl . "/images/" . $data->variable)'

			  ),

Add this code in cgridview




array(

    'header'=>'Foto',

    'type' => 'raw',

    'value' => '$data->displayFoto()'

   ),



Add this funciton in your current model




public function displayFoto(){

// add image path

if($this->foto!='')

   return CHtml::image(Yii::app()->baseUrl . "/images/" . $this->foto);

else

   return "No Image";

}