7.4.1.6 image

image(string $path, array $htmlAttributes = array())

Creates a formatted image tag. The path supplied should be relative to /app/webroot/img/.

<?php echo $html->image('cake_logo.png', array('alt' => 'CakePHP'))?> 
  1. <?php echo $html->image('cake_logo.png', array('alt' => 'CakePHP'))?>

Will output:

<img src="/img/cake_logo.png" alt="CakePHP" /> 

To create an image link specify the link destination using the url option in $htmlAttributes.

<?php echo $html->image("recipes/6.jpg", array(
    "alt" => "Brownies",
    'url' => array('controller' => 'recipes', 'action' => 'view', 6)
)); ?>
  1. <?php echo $html->image("recipes/6.jpg", array(
  2. "alt" => "Brownies",
  3. 'url' => array('controller' => 'recipes', 'action' => 'view', 6)
  4. )); ?>

Will output:

<a href="/recipes/view/6">
    <img src="/img/recipes/6.jpg" alt="Brownies" />
</a>