我有一个代码来显示带有一个图像列的结果。不知怎的,它给了我错误
我写了这样的代码。
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id' => 'photo-grid',
'dataProvider' => $model->search(),
//'filter' => $model,
'columns' => array(
'id',
array(
'name'=>'user_id',
'value'=>'GxHtml::valueEx($data->user)',
'filter'=>GxHtml::listDataEx(User::model()->findAllAttributes(null, true)),
),
array(
'name'=>'regulation_id',
'value'=>'GxHtml::valueEx($data->regulation)',
'filter'=>GxHtml::listDataEx(Regulation::model()->findAllAttributes(null, true)),
),
//'photo_img',
array(
'name' => 'Photo Img',
'type' => 'raw',
'value' => CHtml::image(Yii::app()->controller->createUrl('photo/loadImage', array('id'=>$model->id)),"",array('width'=>50, 'height'=>50)),
),
array(
'class' => 'CButtonColumn',
),
),
)); ?&GT;
任何人都可以帮我如何在CGridView中显示图像吗?
答案 0 :(得分:6)
该级别没有$ model-&gt; id
您需要将其更改为$ data,并确保它是一个字符串,稍后将在单元格呈现时进行评估(如果您保留为非字符串,则表示在创建网格之前对其进行评估)< / p>
'value' => 'CHtml::image(Yii::app()->controller->createUrl(\'photo/loadImage\', array(\'id\'=>$data->id)),"",array(\'width\'=>50, \'height\'=>50))',
答案 1 :(得分:0)
请试试这个,它正在运作:
array(
'name'=>'Image_name_large',
'value'=>'CHtml::image(Yii::app()->request->baseUrl."/uploads/vehiclesimages/".$data->Image_name_large,
"",
array(\'width\'=>100, \'height\'=>100))',
'type'=>'raw',
),