How to show image thumbnail in GridView ?

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 ?

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.

I dont understand what should be included in getThumnailUrl() and getThumbnailOptions()

Could you give me an example?

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.

Ok. But how to get a name of file from related model?




$model->photo->file_name;