rasny92
(Saminiemi)
1
Hi,
I would like to show in GridView small thumbnail from dependent gallery.
In the model:
public function getPhoto()
{
return $this->hasOne(PhotosSmallAd::className(), ['photo_id' => 'ad_id']);
}
And in the GridView I can only display the file name:
[
'label' => 'ad_id',
'attribute' => 'ad_id',
'value' => 'photo.file_name',
],
How to display an image ?
softark
(Softark)
2
Something like this:
[
'label' => 'ad_id',
'attribute' => 'ad_id',
'value' => function ($model, $key, $index, $column) {
return Html::img($model->phpto->getThumbnailUrl(), $model->phpto->getThumbnailOptions());
},
],
Please implement getThumnailUrl() and getThumbnailOptions() in your PhotosSmallAd model.
rasny92
(Saminiemi)
3
I dont understand what should be included in getThumnailUrl() and getThumbnailOptions()
Could you give me an example?
softark
(Softark)
4
getThumbnailUrl() should return the url of the thumbnail, and getThumbnailOptions() should return the img tag attributes like:
[
'width' => 50,
'height' => 30,
'alt' => 'something',
}
Just the same way as you display the main image.
rasny92
(Saminiemi)
5
Ok. But how to get a name of file from related model?
softark
(Softark)
6
$model->photo->file_name;