0

我有以下链接格式,我想使用 Cakephp HTML 助手显示

<a href="product_n1_details.html" title="" class="view_image"> 
 <img src="images/slider/1n.jpg" alt="">
 <div class="link_overlay icon-search"></div>
</a>

我试过什么?

<?php echo $this->Html->link($this->Html->image('products/'.$pro['Product']['display_photo']."<div class=\'link_overlay icon-search\'></div>", array('alt' => $pro['Product']['name'])), array('controller' => 'products', 'action' => 'view', $pro['Product']['id']), array('escape' => false, 'class' => 'view_image') ); ?>

在此处输入图像描述

4

2 回答 2

2

图像助手返回整个<img>标签,因此将div代码放在图像助手调用之后(为清楚起见,请隔开):

echo $this->Html->link(
    $this->Html->image(
        'products/'.$pro['Product']['display_photo'],
        array(
            'alt' => $pro['Product']['name']
        )
    ) . "<div class='link_overlay icon-search'></div>", // put it here!
    array(
        'controller' => 'products',
        'action' => 'view',
        $pro['Product']['id']
    ),
    array(
        'escape' => false,
        'class' => 'view_image'
    )
);
于 2014-07-02T21:34:01.813 回答
1

scrowler 是正确的。

所有 Html 辅助函数都返回字符串,所以如果你想让它自己更干净一点,你可以这样做

$image = $this->Html->image( . . . );
$div   = $this->Html->tag( 'div', ... );

然后终于

echo $this->Html->link( $image . $div, ... );

希望有帮助。

于 2014-07-03T01:58:51.060 回答