在 gridview yii2 中设置宽度图像

2022-01-07 00:00:00 image php yii2 gridview

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

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

解决方案

你可以像例子一样为单元格定义类

<预><代码>['属性' =>'标题','格式' =>'图片','价值' =>函数($数据){返回'you_image.jpeg';},'内容选项' =>['类' =>'来上课']],

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

<预><代码>['属性' =>'标题','格式' =>'html','价值' =>function($data) { return Html::img('you_image.jpeg', ['width'=>'100']);},],

how to set width image in gridview widget in yii2?

I've been using this method to display the image. Image in gridview in yii2

解决方案

You can define class for cells as in example

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

Then set image width using css. If image width can be different, use html format

[
    'attribute' => 'title',
    'format' => 'html',
    'value' => function($data) { return Html::img('you_image.jpeg', ['width'=>'100']); },
],

相关文章