JoenMarz
JoenMarz

Reputation: 143

how to display uploaded image in view using Yii

I'm having trouble in displaying my uploaded image. The image path at [webapp]/images/products/

First: I want to display it inside CCGridView. I wrote:

<?php $this->widget('zii.widgets.grid.CGridView', array(
        'id'=>'image-grid',
        'dataProvider'=>$model->search(),
        'filter'=>$model,
        'columns'=>array(
            'id',
            'title',
            'filename',
            //this is the image displaying part
            array(
                'type' => 'raw',
                'value' => 'CHtml::image(Yii::app()->baseUrl . "/images/products/" . $data->filename)',
            ),
            'product_id',
            //
            array(
                'class'=>'CButtonColumn',
            ),
        ),
)); ?>

But the result only became like this: CCGridView

Second: I also want to display it in view.php

<?php if($model->filename) 
        $path = Yii::app()->baseUrl. '/../images/products/' . $model->id;
    echo CHtml::image($path,
            $model->title,
            array(
                'title' => $model->title,
                'style' => 'margin: 10px;',
    )); ?>

But the result is: view

Please help me solving this. Many thanks!

Upvotes: 1

Views: 3611

Answers (2)

user2883814
user2883814

Reputation: 365

try this maybe help:

CHtml::image(Yii::app()->baseUrl . "/../images/products/" . $data->filename);

and check is exists file with name $data->filename

Upvotes: 2

Satish Rajput
Satish Rajput

Reputation: 49

Please try this..

"value"=>'($data->picture !=="") ? CHtml::image(Yii::app()->request->baseurl."/upload/technician/".$data->picture,"",array(\'width\'=>100, \'height\'=>50)) : ""',

I Hope it will help you...

Upvotes: 0

Related Questions