1

I have this code with images src array so i want to display all images from this array

    <?php
        $image = explode(',',$model->image_url);
    ?>
    <?=
        DetailView::widget([
        'model' => $model,
        'attributes' => [
            'request_design_id',
            'email',
            'mobile_no',
            'description',
            [
                'attribute'=>'photo',
                'value'=> Yii::getAlias("@web") . "/" .$image[0],
                'format' => ['image',['width'=>'100','height'=>'100']],
            ],
            'created_at',
        ],
    ]) ?>

I have only print one image. but i want to display all images from $image array

  • You want to display all images inside `photo` attribute? – Insane Skull Dec 16 '22 at 09:25
  • you can check this question answer maybe this will help you https://stackoverflow.com/questions/38635197/yii2-display-multiple-images-in-gridview-row Or you can go with the below answer with this modification [ 'attribute'=>'photo', 'value'=> function ($model) use ($images) { $html = ''; foreach ($images as $img) { $html .= Html::img($img, ['width' => '100px', 'height' => '100px']) } return $html; }, 'format' => 'raw', ], – Govind Feb 13 '23 at 11:51

1 Answers1

0

You can use the multiple html img tag with the concatenation and use the format as raw.

        [
            'attribute'=>'photo',
            'value'=> function ($model) {
               $html = ''; 
               foreach ($images as $img) { 
                 $html .= Html::img($img, ['width' => '100px', 'height' => '100px']) 
               } 
               return $html; 
            },
            'format' => 'raw',
         ],
Community
  • 1
  • 1
sesa
  • 31
  • 3
  • Suggested edit [ 'attribute'=>'photo', 'value'=> function ($model) use ($images) { $html = ''; foreach ($images as $img) { $html .= Html::img($img, ['width' => '100px', 'height' => '100px']) } return $html; }, 'format' => 'raw', ], – Govind Feb 13 '23 at 11:57