Image in gridview in yii2

前端 未结 9 1832
梦毁少年i
梦毁少年i 2020-12-16 04:34

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?

         


        
9条回答
  •  鱼传尺愫
    2020-12-16 05:09

    It is simple you can just declare it in your index file as below.

    [
                'label' => Your Label Here',  
                'format' => 'raw',   
                'value' => function ($data) {
                     $images = '';
    
                    $images = $images.Html::img(\Yii::$app->request->BaseUrl.'/your-path-here/'.$date->getImagefilename(),['alt'=>'','width'=>'30','height'=>'30', 'data-toggle'=>'tooltip','data-placement'=>'left','title' => $name->pictogram_comment ,'style'=>'cursor:default;']);
                    return ($images);
    
                }
                ],
    

    You will have to get image instance from your model. If required example please comment, will get back on that.

提交回复
热议问题