Did you know? image() can has url!

Now this is a quick one here. Most of you know the following code from the default.ctp after you “just baked” the app.

echo $html->link(
	$html->image('cake.power.gif', array('alt'=> __("CakePHP...", true), 'border'=>"0")),
	'http://www.cakephp.org/',
	array('target'=>'_blank'), null, false
);

This displays the small “CakePHP Power” badge with a link to their website. Much code for just a image surrounded with a link, eh?

The $html->image() method has a option called ‘url’ that automatically does this for you. Only limitation is that you can’t pass attributes to the link tag. But who really needs “target=_blank” in XHTML world anyway?

So here’s the same thing, only without the clutter:

echo $html->image('cake.power.gif', array('url' => 'http://www.cakephp.org', 'alt' => __('CakePHP...', true), 'border' => 0));

Tada! There you have it. Of course ‘url’ accepts arrays and everything else since it passes the value straight into Helper::url();

Enjoy