kicaj
kicaj

Reputation: 2968

CakePHP html helper imgage links

In Cake, we can add url in image() like this:
$this->Html->image('image src...', array('url' => 'some address...');
and output is:
<a href="some address..."><img src="image src..." /></a>.

How to add class and others attributes to a tag?

Upvotes: 1

Views: 941

Answers (1)

Dave
Dave

Reputation: 29121

echo $this->Html->link(
    $this->Html->image($imageSrc, array(
        'class'=>'class_of_image',
        'height' => '50',
        'width' => '100',
        'alt' => 'awesome close-up of me eating pizza'
    )),
    array(
        'controller' => 'your_controller',
        'action' => 'the_action'
    ),
    array(
        'class' => 'class_of_anchor',
        'escape' => false //to allow the image tag within the link
    )
);

Feel free to make any/all parts of this into a single line - but for StackOverflow reasons, it's easier to read like this.

Upvotes: 6

Related Questions