如何在CGridview中添加图像 [英] How to add an image in CGridview

查看:92
本文介绍了如何在CGridview中添加图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我对表格gridview的索引:

$ $ $ this-> widget('zii.widgets。 grid.CGridView',array(
'id'=>'tblvehicleimagegrid',
'dataProvider'=> $ model-> search(),
'filter'=> $ b $'b'column'=>数组(

'serial_no',
array(
'name'=>'image',
'type'=>'raw',
'value'=> CHtml :: image(Yii :: getPathOfAlias('webroot')。/ images / originals / images.jpg),

),

'line_no',
..........
.........

出现错误



需要一些帮助。

解决方案

请看此页面



如果您在下面的Yii论坛上写下代码:

  $ this-> widget('zii.widgets.grid.CGridView',array(
'dataProvider'=> $ dataProvider,$ b $'columns'=> array(

array(
'name'=>'Flag',
'type'=>'image',
'value'=>'CHtml :: image( (
















$ b $

然后你会得到这个结果:

 < img alt =src =< img src =images / flags / England.gifalt =country/>/> 

注意不兼容的元素?



换句话说,您需要将列声明中的'type'设置为'html',以便CGridView知道要查找HTML,这就是CHTML :: image会给你的。



编辑:



我知道Yii文档可能有点不清楚,但是如果您查看代码,它会通常是有道理的。在这种情况下, CHTML :: image()的文档告诉我们它会返回一个图片标签,具体来说就是。

This is my index for the gridview of the table:

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'tblvehicleimagegrid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(

    'serial_no',
    array(
      'name'  =>'image',
        'type'=>'raw',
        'value'=> CHtml::image(Yii::getPathOfAlias('webroot')."/images/originals/images.jpg"),

    ),

    'line_no',
..........
.........

Comes with an error

Need some help in this.

解决方案

Take a look at this page.

If you write the code as bettor did on the Yii forums:

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'columns'=>array(

            array(
              'name'=>'Flag',
                'type'=>'image',
                'value'=>'CHtml::image("images/flags/".$data->country.".gif", "country")',
            ),

    ),
));

Then you'll end up with this:

<img alt="" src="<img src="images/flags/England.gif" alt="country" />"/>

Note the incompatible elements?

In other words, you're going to need to set the 'type' in your column declaration to 'html,' so that CGridView knows to look for HTML, which is what CHTML::image is going to give you.

edit:

I know the Yii docs can be a little unclear, but if you look at the code, it'll often make sense. In this case, the docs for CHTML::image() do tell us that it returns an image tag, specifically.

这篇关于如何在CGridview中添加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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