Display Image

Hi Yii Users,

Can anyone guide me how do I go about creating a function in my model to display an image from another table?




'columns'=>array(

		array(

			'name' => 'image',

              		'type' => 'raw',

              		'value' => 'CHtml::link($data->product_name,Yii::app()->createUrl("stock/view",array("id"=>$data->primaryKey)))',

              		'filter'=>false,

		),



Currently I am displaying product_name that is a link to individual view page. The product_name can also be found in another table that stores that image.

Anyone?

Million thanks in advance.

there you go




<?php

// model


public function getProductImage()

{

	// your logic for image

}




// change your grid column


array(

    'name' => 'image',

    'type' => 'raw',

    'value' => 'CHtml::link($data->product_name,Yii::app()->createUrl("stock/view",array("id"=>$data->primaryKey)))',

    'filter'=>false,

),


 // like so

'columns' => array(

	'productImage',

	// ...

)

hi

in your model :




public function getImgShow(){

$model = myModel::model()->find(...);

 $str='<img src="'. Yii::app()->request->baseUrl.'/images/'.$model ->img.'.png" />';

echo $str;

}



in your view -> gridview :




array(

'name'=>'img'

                        'value' =>'$data->getImgShow()',

                        

                          

			 ),






array(

			'name' => 'image',

              		'type' => 'raw',

              		'value' => 'CHtml::link(CHtml::image(Yii::app()->request->baseUrl."/images/".Joborder::model()->findByAttributes(array("job_order"=>$data->product_name))->image,"alt",array("width"=>100)),Yii::app()->createUrl("stock/view",array("id"=>$data->primaryKey)))',

              		//'filter' => CHtml::activeTextField($model, 'image', array('class'=>'form-control form-filter input-sm')),		

              		'filter'=>false,

		),




Thank you all for the pointers! Managed to solve it in no time. :)