如何在 yii2 的 gridview 小部件中设置宽度图像?
我一直在使用这种方法来显示图像。 yii2中gridview中的图像
您可以为单元格定义类,如示例
[
'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']); },
],
利用:
'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;
}
利用
'format' => ['image',['width'=>'100','height'=>'100']],
例子:
[
'attribute' => 'image',
'format' => ['image',['width'=>'100','height'=>'100']],
'value' => function($dataProvider) { return $dataProvide->image; },
],