我有一个写代码来显示一个图像列的结果.不知怎的,它给了我错误
我写了这样的代码.
<?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',
),
),
Run Code Online (Sandbox Code Playgroud)
)); ?>
任何人都可以帮我如何在CGridView中显示图像?
该级别没有$ model-> id
您需要将其更改为$ data,并确保它是一个字符串,稍后将在单元格呈现时进行评估(如果您保留为非字符串,则表示在创建网格之前对其进行评估)
'value' => 'CHtml::image(Yii::app()->controller->createUrl(\'photo/loadImage\', array(\'id\'=>$data->id)),"",array(\'width\'=>50, \'height\'=>50))',
Run Code Online (Sandbox Code Playgroud)