How to put an image in GridView in yii2?I have the following code. But its not displaying the image as it is not giving any image url. Where to put the image url?
<?php echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'c_id',
'name:ntext',
'description:ntext',
array(
'format' => 'image',
'attribute'=>'logo',
),
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
Try like,
And in your model,
Don't know this is the right way or not.But this works for me.
It is simple you can just declare it in your index file as below.
You will have to get image instance from your model. If required example please comment, will get back on that.
Use this:
Yii 2 has built-in helper for building urls. You can bulld the url to image by path too (by passing second parameter
$scheme
).So I recommend using this:
GridView:
Model:
You can try this one:
You can also use:
'@web' is a predefined path aliases.
'urlManager->CreateUrl()' do something more than resolving aliases.