cakephp图像链接与类关联

时间:2014-06-03 10:43:20

标签: php cakephp html-helper

使用Cakephp html帮助器,我怎样才能在蛋糕中做到这一点?

<a class="logo" href="index.php">
 <img src="img/logo.png">
</a>
我这样做了:

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而不是假定的锚。

2 个答案:

答案 0 :(得分:3)

你应该在图像周围使用$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) 
);

答案 1 :(得分:2)

echo $this->Html->link($this->Html->image('image.jpg', ['class' => 'imgClass']), ['controller' => 'contents', 'action' => 'home'], ['escape' => false, 'class' => 'linkClass']);