yii cgridview 如何显示图片
2013-11-03 17:05
676 查看
发布的新闻或介绍里有图片,图片存的是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代码来执行的 记录一下,方便查看,也方便大家解决问题
相关文章推荐
- php:Forbidden You don’t have permission to access / on this server.
- php补充安装扩展支持
- 一个PHP病毒
- 利用SmtpClient发送邮件
- 代码生成-php代码生成-专注代码生成30年.
- ZendFramework2 结合 Doctrine
- 开发者必备,超实用的PHP代码片段!
- php代码
- PHP中实用的模式之【门面模式】
- PHP本地环境搭配——WAMP不能启动, 一直处于红色图标或者橙色图标的解决办法
- 开发者必备,超实用的PHP代码片段!
- RHCE系列之ntp服务器----实践篇
- pure-ftpd无法停止的暂时解决方法
- php 数据转码 函数iconv
- 在PHP上显示JFreechart画的统计图方法
- ubunto下安装LAMP(4)
- RHCE系列之ntp服务器----理论篇
- IIS7以上版本去掉伪静态去掉index.php方法
- PHPThumb处理图片
- 细察 PHP V5.3.0 特性