在 gridview yii2 中设置宽度图像 [英] Set width image in gridview yii2

查看:19
本文介绍了在 gridview yii2 中设置宽度图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 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']); },
],

这篇关于在 gridview yii2 中设置宽度图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆