Display image in grid view YII2

In Yii 2 there are many function including built-in helper for building urls. So we can easily bulld the url to image by path too .

To display the image in grid view :

‘attribute’ => ‘image’,
‘format’ => ‘html’,
‘value’ => function($data) {
return Html::img(\Yii::$app->request->BaseUrl.’/uploads/’.$data->image,[‘width’=>100]);

To display the image in DetailView :
‘format’ => [‘image’,[‘width’=>’100′,’height’=>’100’]],

Leave a Reply