在 kartik 网格中显示图像显示路径

Displaying an image in kartik grid shows the path

我有一个网格,我想实现一个图像,但它总是 returns 图像的路径

这是代码:

[
    'attribute' => 'picture',
    'value'=>function($data) { return $data->imageurl; },
    'value' => function ($data) {
        return Html::img(Yii::getAlias('@web').'/images/user_accounts.png',
            ['width' => '70px']);
    },

],

上面的想法是从This link得到的,但它失败了

我也试过了:

[
    'attribute' => 'picture',
    'value'=>function($data) { return $data->imageurl; },

],

并添加了

public function getImageurl()
  {
      return \Yii::$app->request->BaseUrl.'/images/user_accounts.png';
  }

但是还是无法将图片显示到网格中

这是显示的内容

使用 DataColumn class 的 format 属性,默认情况下它使用文本格式,因此内容显示为文本而不是 html。使用原始或 html 格式化程序

试试这个:

[
    'attribute' => 'picture',
    'format' => 'html',    
    'value' => function ($data) {
        return Html::img(Yii::getAlias('@web').'/images/'. $data['imageurl'],
            ['width' => '70px']);
    },
],
>>>This may be helpfull too...  
          [  
            'attribute' => 'picture',  
            'format' => 'html',  
            'value' => function ($data) {  
                    return Html::img($data->imageurl,['width' => '80px']);  
             },  
             'filterType' => GridView::FILTER_SELECT2,  
             'filter' => '',  
             'filterWidgetOptions' => [  
                'pluginOptions' => ['allowClear' => true],  
              ],  
              'filterInputOptions' => ['placeholder' => 'Image Url'],  
          ],