You are viewing revision #3 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.
This is a simple example of how we can display images in CGridviews.Imagine that you have an image field in your table ie either a location field or a blob type field used to store the images.
$assetsDir = dirname(__FILE__).'/../assets'; /*Assume that you have a folder named assets inside the protected folder used to store the images */
<?php $this->widget('bootstrap.widgets.CGridView', array(
'type'=>'striped bordered condensed',
'id'=>'expenses-grid',
'dataProvider'=>$model->search(),
'template'=>"{items}",
'columns'=>array(
array(
'name'=>'image',
'type'=>'html',
'value'=>'(!empty($data->image))?CHtml::image(Yii::app()->assetManager->publish('.$assetsDir.'$data->image),"",array("style"=>"width:25px;height:25px;")):"no image"',
),
array(
'class'=>'bootstrap.widgets.BootButtonColumn',
'template' => '{update} {delete}',
'buttons' => array(
'update' => array(
'label'=> 'Update',
'options'=>array(
'class'=>'btn btn-small update'
)
),
'delete' => array(
'label'=> 'Delete',
'options'=>array(
'class'=>'btn btn-small delete'
)
)
),
'htmlOptions'=>array('style'=>'width: 80px'),
)
),
)); ?>
-Sirin k
need bootstrap
need bootstrap :http://www.yiiframework.com/extension/bootstrap/ ?
No need of bootstrap
Its not necessary yout to use the bootstrap but just used it my example.thats all.
can be achieved also using this extension
I've just released http://www.yiiframework.com/extension/pclinkbutton/, which does very similar to what you needed to.
Fine.
thanks for the extension.
excellent
@sirin k: another excellent example. I love it and it works great. How would I go about displaying a button with a modal pop-up of the image?
I am using bootstrap if that helps.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.