User1988
User1988

Reputation: 1997

Displaying image in a CGridView column

Here is my code

$img= Yii::app()->params['questionImageUploadURL'].$model->q_type."/".$model->qImgRel->image_name;
<?php $this->widget('zii.widgets.CDetailView', array(
    'data'=>$model,
    'attributes'=>array(
        'id',
        'q_nationality_id',
        'q_type',
        'q_name',
        array(
            'name'  => 'q_image_id',
            'value' => (is_object($model->qImgRel)?CHtml::image($img,""):""),
            'visible'=>(is_object($model->qImgRel)?true:false),
        ),
        'opt1',
        'opt2',
        'opt3',
        'opt4',
        'answer',
    ),
)); ?>

Its display me like this enter image description here

I dnt get image in my view plz help me Thanks in advance :)

Upvotes: 1

Views: 8272

Answers (4)

Akshaya Moorthy
Akshaya Moorthy

Reputation: 307

<? php

$w="50px";$h="50px";

$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'redcliffe-cms-grid',

    'dataProvider' => $model->search(),

    'filter' => $model,

    'columns' => array(
        'title','date','description',

       array(
            'filter' => '',
            'type' => 'raw',   
            'value' => 'CHtml::image(Yii::app()->baseUrl ."/upload/" .$data>image,"",array(\'width\'=>\'50\', \'height\'=>\'50\'))', 
             ),
        array(
            'class' => 'CButtonColumn',
             ),
    ),
));
? >

Upvotes: 2

WebDevPT
WebDevPT

Reputation: 588

A simple

                array(        
                 'name'=>'filename',
                 'value'=> CHtml::image(Yii::app()->request->baseUrl.'/path/'.$model->filename),
                 'type'=>'raw',
            ),

would do the trick (don't forget the type 'raw')

Upvotes: 0

Rohit13
Rohit13

Reputation: 299

Try this :-

 array(
            'name'  => 'q_image_id',
            'type'  => 'raw'
            'value' => (is_object($model->qImgRel)?CHtml::image($img,""):""),
        ),

Upvotes: 2

Related Questions