与类关联的cakephp图像链接

与类关联的cakephp图像链接,php,cakephp,html-helper,Php,Cakephp,Html Helper,使用Cakephp html助手,如何在cake中实现这一点 <a class="logo" href="index.php"> <img src="img/logo.png"> </a> 这将执行以下html代码: <a href="/Root/Home/index/"> <img class='logo' alt="ArtBid Logo" src="/artbid/img/logo.png"> </a> 但是

使用Cakephp html助手,如何在cake中实现这一点

<a class="logo" href="index.php">
 <img src="img/logo.png">
</a>
这将执行以下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) 
);

您应该在图像周围使用
$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(“logo.png”,array(“alt”=>“logo”)),array(“class”=>“logo”,“url”=>array(“controller”=>“Home”,“action”=>“index”));有些东西不起作用:尝试添加
array('escape'=>false)
在使用classI的数组之后我尝试了你的代码但它不起作用,你是说:echo$this->Html->link($this->Html->image(“logo.png”,array(“alt”=>“logo”)),array(“class”=>“logo”,“url”=>array(“controller”=>“Home”,“action”=>“index”));有些地方不起作用:尝试在类的数组之后添加
array('escape'=>false)
echo $this->Html->link($this->Html->image('image.jpg', ['class' => 'imgClass']), ['controller' => 'contents', 'action' => 'home'], ['escape' => false, 'class' => 'linkClass']);