Enthu
(Zackrocha14)
October 8, 2014, 8:35am
1
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.
alirz23
(Alirz23)
October 8, 2014, 10:06am
2
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',
// ...
)
negar
(Nar8591)
October 8, 2014, 11:55am
3
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()',
),
Enthu
(Zackrocha14)
October 9, 2014, 2:47am
4
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.