Click-Able Image And Link To Another Page

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.

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/');

?>



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 :D