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 :

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

To display the image in DetailView :
[php]
[
‘attribute’=>’image’,
‘value’=>(\Yii::$app->request->BaseUrl.’/uploads/tips/’.$model->image),
//’value’=>$model->image,
‘format’ => [‘image’,[‘width’=>’100′,’height’=>’100’]],
],
[/php]

Leave a Reply