yee123
(Yapsiongyee)
1
Hi, guys! Does anyone knows how to make a click-able image and once I click on the image, it will direct me to another page.
Here’s my code:
<?php
echo CHtml::link(CHtml::image(Yii::app()->request->baseUrl.'/images/msc2.png',"yahoo",array('http://www.yahoo.com/')));
?>
The image can be clicked but it doesn’t go to the page with the url of ‘http://www.yahoo.com/’. Am I doing anything wrong here?? Thanks in advance.
Keith
(Kburton)
2
Yes, here’s your code more clearly formatted:
<?php
echo CHtml::link(
CHtml::image(
Yii::app()->request->baseUrl.'/images/msc2.png',
"yahoo",
array('http://www.yahoo.com/')
)
);
?>
You’re passing the URL into CHtml::image() instead of CHtml::link().
Besides that, you should pass the URL in as a string rather than an array when you have the complete URL:
<?php
echo CHtml::link(
CHtml::image(Yii::app()->request->baseUrl.'/images/msc2.png', "yahoo"),
'http://www.yahoo.com/');
?>
yee123
(Yapsiongyee)
3
Oh, no! What a stupid mistake that I have made. Thanks a lot, Keith! It works well to me. Thanks for your help. Have a nice day 