// you’re reading...

PHP Related Links

CakePHP 1.2: $html->link with html or image.

In CakePHP 1.1 if you need to display an image or piece of HTML with a link to an action, you need to instruct cake NOT to escape the contents of the “Title” attribute with the last false statement like this:

e(
$html->link( 
	$html->image("add.gif"), 
	array('action' => 'add'), 
	array(), 
	null, 
	false ));

In CakePHP 1.2 you could rewrite this to:

e(
$html->link( 
	$html->image("add.gif"), 
	array('action' => 'add'), 
	array('escape' => false)));
Tags: ,

Discussion

Comments are disallowed for this post.

  1. great tip, thank you.

    Posted by Bill | December 20, 2007, 9:12 pm
  2. The image is properly displayed, but not inside the link!

    echo $html->link(
    $html->image(”gl.banner.png”),
    ‘/info’,
    array(),
    null,
    false );

    When I look at the actual html output though, you’ll see ;
    <img src=”/img/gl.banner.png” /><a href=”/index.php?/info” ></a>

    Any Advice?

    Posted by Eddie | May 16, 2008, 5:48 pm
  3. Follow up!

    Be sure that in your core.php cofiguration to check the following line;

    define(’AUTO_OUTPUT’, false);

    must be false in order for this to work.

    Posted by Eddie | May 16, 2008, 5:51 pm
  4. top entry cheers work for me first time… why this isnt in the cake docs who knows :D

    Posted by Sir P | August 23, 2008, 9:22 pm