Question

I have stored image in Images Folder(root) In my Yii project. I want to show image in CDetailView that is in protected/view/college

my code

array(
            'label'=>'CollegeLogo',
            'type'=>'raw',
            'value'=>CHtml::image("../".Yii::app()->baseUrl."/Images/".$model->CollegeLogo),

        ),

it is not working

Was it helpful?

Solution 2

remove "../" in your code. Baseurl will return path from root folder.

'value'=>CHtml::image(Yii::app()->baseUrl."/Images/".$model->CollegeLogo),

OTHER TIPS

<?php 

$this->widget('zii.widgets.CDetailView', array(

    'data'=>$model,
    'attributes'=>array(
        'title',
        'date',
        'description',
         array(
            'type' => 'raw',
            'value'=>CHtml::image(Yii::app()->baseUrl."/upload/".$model->image,'alt',array("width"=>"50px" ,"height"=>"50px"))
            ),
        'time',
        'user_id',
    ),
)); ?>

try this

'value'=>CHtml::image(Yii::app()->getBaseUrl(true) . '/Images/'.$model->CollegeLogo),

The simplest way is to use the string format "Name:Type:Label" with the Image Type

<?php
'attributes' => array(
  "CollegeLogo:image",
  //...
),

If the CollegeLogo attribute doesn't return the absolute url, I would create a virtual attribute in the model that returns it:

public function getCollegeLogoUrl() {
    return "../".Yii::app()->baseUrl."/Images/".$model->CollegeLogo;
}

And then use it in the widget:

<?php
'attributes' => array(
  "collegeLogoUrl:image",
  //...
),

This code worked

array(
            'label'=>'CollegeLogo',
            'type'=>'raw',
            'value'=>CHtml::tag('img',
                array("title"=>"CollegeLogo",
                "src"=>Yii::app()->baseUrl."/CollegeImages/".$model->CollegeLogo,
                "style"=>"height:70px")
            )
        ),
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top