Making Clickable Images on CakePHP
Hello again,
Yesterday, i stumbled upon this problem on how am i suppose to create an image with a link on it. I needed to know it because of my goal. I wanted to use images as my buttons to navigate the admin pages. So without further ado, here’s how:
1. We will use HTML Helpers Image and Link, and we shall combine this 2.
2. For Image,
Syntax:
$html->image(string $path, array $htmlAttributes, boolean $return = false);
Example:
$html->image(‘/img/images/cancel.png’, array(‘class’ => ’save_button’));
3. For Link,
Syntax:
$html->link(string $title, string $url, array $htmlAttributes, string $confirmMessage = false, boolean $escapeTitle = true, boolean $return = false);
Example:
$html->link(‘SAVE’, ‘/registers’, array(), false, false, false);
4. So to make an image clickable,
<?php echo $html->link($html->image(‘/img/images/cancel.png’,array(‘class’ => ’save_button’)), ‘/registers’, array(), false, false, false); ?>
That’s it. I hope this will help you in the future.
Yesterday, i stumbled upon this problem on how am i suppose to create an image with a link on it. I needed to know it because of my goal. I wanted to use images as my buttons to navigate the admin pages. So without further ado, here’s how:
1. We will use HTML Helpers Image and Link, and we shall combine this 2.
2. For Image,
Syntax:
$html->image(string $path, array $htmlAttributes, boolean $return = false);
Example:
$html->image(‘/img/images/cancel.png’, array(‘class’ => ’save_button’));
3. For Link,
Syntax:
$html->link(string $title, string $url, array $htmlAttributes, string $confirmMessage = false, boolean $escapeTitle = true, boolean $return = false);
Example:
$html->link(‘SAVE’, ‘/registers’, array(), false, false, false);
4. So to make an image clickable,
<?php echo $html->link($html->image(‘/img/images/cancel.png’,array(‘class’ => ’save_button’)), ‘/registers’, array(), false, false, false); ?>
That’s it. I hope this will help you in the future.


September 11th, 2008 at 5:03 am Hi I would say you would be better for the URLs in more cake way, i.e.
echo $html->link($html->image(’images/cancel.png’,array(’class’ => ’save_button’)), array(‘controller’=>’registers’,'action’=>’index’, array(), false, false, false);
although it would work your way too.
Just cleaner code in my opinion and for images it uses the default image folder syntax.
October 9th, 2008 at 5:00 am even more cleaner code
you can add url in the options array for $html->image.
$html->image(’images/cancel.png’,array(’class’ => ’save_button’, ´url´ => array(’controller’=>’registers’,’action’=>’index´))
January 23rd, 2009 at 3:10 am Or you can try this:
image(“images/cancel.png”, array(
“alt” => “Cancel”,
‘url’ => array(‘controller’ => ‘registers’, ‘action’ => ‘index’)
)); ?>
April 30th, 2009 at 1:20 pm [...] this tutorial from Here Check this page also Possibly related posts: (automatically generated)always use html->linkReal-Life Great [...]