yii cgridview 如何显示图片

发布的新闻或介绍里有图片,图片存的是Url地址,通过yii的cgridview,默认是数据库里存的啥就显示啥,如何把url地址转为图片?直接上代码

<?php
	$data = $model->search();//全部数据 P.S 分页设置在News.php里 aptionSearch方法实现
	//分页显示数据,如下所写,分页有效,筛选无效
	/*$data = new CActiveDataProvider('News', array(
    	'pagination' => array(
        	'pageSize' => 2,
        ),
    ));*/
	$filter = Category::model()->findAll();
	$this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'news-grid',
	'dataProvider' => $data,
	'filter'=>$model,
	'columns'=>array(
		// 'n_image',
		array(
            'name'=>'n_image',
            'type'=>'html',
            'value'=>'(!empty($data->n_image))?CHtml::image("/".$data->n_image,"",array("style"=>"width:100px;height:100px;")):"暂无图片"',
        ),
		// 'n_content',
		array(
			'class'=>'CButtonColumn',
			//自定义删除提示
			'deleteConfirmation'=>"js:'ID为 '+$(this).parent().parent().children(':first-child').text()+' 的记录将被删除,确定删除?'",
		),
	),
)); ?>
'value'=>'(!empty($data->n_image))?CHtml::image("/".$data->n_image,"",array("style"=>"width:100px;height:100px;")):"暂无图片"', 
这里是通过CHtml的方法image来把url转成图片,写的时候要注意'' 这里的内容,必须是能够执行的php代码,在内部yii是通过 eval() 这个函数把内容转换为了php代码来执行的
记录一下,方便查看,也方便大家解决问题
posted @ 2013-11-03 17:05  Debm.Zhang  阅读(1102)  评论(0编辑  收藏  举报