0

I'm currently using an image in my navbar but I also want to make clicking this return to the home page.

I thought adding ,array('href' => 'imagepath.png') would work but had no luck so far and it seems to break the page!

this is the code I am trying to change.

 echo CHtml::image(Yii::app()->request->baseUrl.'imagepath'); 

Keep in mind I have tried

echo CHtml::image(Yii::app()->request->baseUrl.'imagepath',
array('href' => 'imagepath')); 

Also trying

echo CHtml::image(Yii::app()->request->baseUrl.'imagepath'); 
echo CHtml::link($image,array('baseurl/page','id'=>'page_id'));

Answer : To get an image to link back to the homepage or chosen baseurl.

$img= CHtml::image(Yii::app()->baseUrl.'/imagepath');
$link = CHtml::link($img, Yii::app()->request->baseUrl);
echo $link;
Alex
  • 673
  • 3
  • 9
  • 22

2 Answers2

2

Try this

$img= CHtml::image(Yii::app()->baseUrl.'/imagepath','altText',array('height'=>100,'width'=>100));
$link = CHtml::link($img, array('baseurl/page','id'=>'page_id'));
echo $link;
Let me see
  • 5,063
  • 9
  • 34
  • 47
0

You need to have a <a> and have a <img> inside it. So I think it's better to use normal html in your case:

<a href="<?php echo Yii::app()->createUrl('baseurl/page', array('id'=>'page_id')); ?>">
   <img src="<?php echo Yii::app()->baseUrl.'imagepath'  ?>" />
</a>
hamed
  • 7,939
  • 15
  • 60
  • 114