6

我尝试使用 FormHelper..in cakephp 制作带有链接的图像。下面是我的脚本:

<?php 
    echo $this->Html->link($this->Html->image('images/view-more-arrow.png') . ' ' . __('View More'),array('controller' => 'zones', 'action' => 'index'), array('escape' => false));
?>

输出:

<a href="/project_folder/trunk/zones"><img src="/project_folder/trunk/img/images/view-more-arrow.png" alt=""> View More</a>

预计:

 <a href="/project_folder/trunk/zones"><img src="/project_folder/trunk/images/view-more-arrow.png" alt=""> View More</a>

我的图像目录路径是 project_folder/app/webroot/images。我不知道为什么它需要 img/ 自动。

先感谢您..

我引用了这个链接: Cakephp html link with image + text, without using css

4

2 回答 2

5

您可以在路径的开头使用斜杠,因为它是相对于 app/webroot 目录的:

echo $this->Html->link($this->Html->image('/images/view-more-arrow.png') . ' ' . __('View More'),array('controller' => 'zones', 'action' => 'index'), array('escape' => false));
于 2013-05-22T09:34:43.830 回答
0

你也可以试试这个,它非常适合我。

$hd = $this->Html->image('hd.jpg',array('alt'=>'harley Davidson', 'border'=>'0', 'width'=>'450', 'height'=>'250'));
echo $this->Html->link($hd,array('controller'=>'Posts', 'action'=>'add'), array('escape'=>false));

在这里$hd,我定义了图像的路径,然后我用它来建立链接。

于 2015-11-30T12:08:33.253 回答