Display Image from database in yii2


how can I display images from database to gridviewcolumn in yii 2? help me please, my page display image name from database instead of image.


It is only the names that are saved in the database. As long as these match real image files, they can be included in gridview or any other display based on $model. Assuming that your image attribute is called ‘yourimage’

//'yourimage', <--Replace this line  with array as below

 ['label' => 'Your Image',

   'format' => ['image',['width'=>'50']], 





You can change width as needed.

I did it, but don’t work for me, here is my code


use yii\helpers\Html;

use yii\grid\GridView;

/* @var $this yii\web\View */

/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Items');

$this->params['breadcrumbs'][] = $this->title;


<div class="items-index">

    <h1><?= Html::encode($this->title) ?></h1>


        <?= Html::a(Yii::t('app', 'Create Items'), ['create'], ['class' => 'btn btn-success']) ?>


    <?= GridView::widget([

        'dataProvider' => $dataProvider,

        'columns' => [

            ['class' => 'yii\grid\SerialColumn'],









            ['label' => 'Item Images',

               'format' => ['image',['width'=>'50']], 






              'attribute' => 'cat_id',

              'value' =>  'cat.cat_name',


            ['class' => 'yii\grid\ActionColumn'],



    ]); ?>




return your image url properly?