8

如何在 yii2 的 gridview 小部件中设置宽度图像?

我一直在使用这种方法来显示图像。 yii2中gridview中的图像

4

3 回答 3

13

您可以为单元格定义类,如示例

[
    'attribute' => 'title',
    'format' => 'image',
    'value' => function($data) { return 'you_image.jpeg'; },
    'contentOptions' => ['class' => 'come-class']
],

然后使用 css 设置图像宽度。如果图像宽度可以不同,请使用 html 格式

[
    'attribute' => 'title',
    'format' => 'html',
    'value' => function($data) { return Html::img('you_image.jpeg', ['width'=>'100']); },
],
于 2014-04-05T19:17:41.380 回答
3

利用:

'value' => function($data) {
        return Html::img($data->imageurl,['width'=>100]);
   },

在你的模型中:

  /*
    Return Image url path
  */
   public function getimageurl()
   {
      // return your image url here
      return \Yii::$app->request->BaseUrl.'/uploads/'.$this->ImagePath;
   }
于 2015-03-10T13:09:52.733 回答
2

利用

'format' => ['image',['width'=>'100','height'=>'100']],

例子:

[           
      'attribute' => 'image',
      'format' => ['image',['width'=>'100','height'=>'100']],
      'value' => function($dataProvider) { return $dataProvide->image; },


],
于 2016-10-28T08:00:38.873 回答