2016-10-11 99 views
0

我有一個網格,我想實現的圖像,但它始終是路徑回圖像顯示在卡爾蒂克格的圖像顯示的路徑

這是代碼:

[ 
    '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'; 
    } 

但它仍然無法顯示圖像到電網

這就是顯示 enter image description here

回答

1

試試這個:

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

由於格式作品 –

1

使用DataColumn類的format屬性,默認情況下它使用文本格式,所以內容顯示爲文本而不是html。使用原料或HTML格式化

0
>>>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'], 
      ],