Reputation: 2790
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
Upvotes: 1
Views: 3806
Reputation: 307
<?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',
),
)); ?>
Upvotes: 3
Reputation: 2790
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")
)
),
Upvotes: 0
Reputation: 2317
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",
//...
),
Upvotes: 0
Reputation: 5094
try this
'value'=>CHtml::image(Yii::app()->getBaseUrl(true) . '/Images/'.$model->CollegeLogo),
Upvotes: 1
Reputation: 8840
remove "../"
in your code. Baseurl will return path from root folder.
'value'=>CHtml::image(Yii::app()->baseUrl."/Images/".$model->CollegeLogo),
Upvotes: 2