cakephp图片链接与类相关联


cakephp Image Links with class associated

使用Cakephp html helper,我如何在蛋糕中做到这一点?

<a class="logo" href="index.php">
 <img src="img/logo.png">
</a>

i did this:

echo $this->Html->image("logo.png", array( 
    "alt" => "Logo", 
    "class" => "logo", 
    'url' => array( 
        'controller' => 'Home', 
        'action' => 'index'
    )
));

这将做以下HTML代码:

<a href="/Root/Home/index/">
<img class='logo' alt="ArtBid Logo" src="/artbid/img/logo.png">
</a>

但是类'logo'指向img而不是锚

您应该在图像周围使用$this->Html->link()并在那里设置类。

echo $this->Html->link(
    $this->Html->image("logo.png", array( 
        "alt" => "Logo"
    )),  
    array("controller" => "Home", "action" => "index"),
    array("class" => "logo", "escape" => false) 
);
echo $this->Html->link($this->Html->image('image.jpg', ['class' => 'imgClass']), ['controller' => 'contents', 'action' => 'home'], ['escape' => false, 'class' => 'linkClass']);