1

Cake では、次のように image() に URL を追加できます。
$this->Html->image('image src...', array('url' => 'some address...');
出力は:
<a href="some address..."><img src="image src..." /></a>です。

クラスやその他の属性をaタグに追加するには?

4

1 に答える 1

6
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
    )
);

この部分の一部またはすべてを 1 行にまとめて構いませんが、StackOverflow の理由から、このようにすると読みやすくなります。

于 2013-03-24T00:04:16.750 に答える