6

I tried to made image with link using FormHelper..in cakephp. Below are my script:

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

Output:

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

Expect:

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

My image directory path is project_folder/app/webroot/images. I don't know why its take img/ automatic.

Thank you in Advance..

I refereed this link: Cakephp html link with image + text, without using css

Community
  • 1
  • 1
Pank
  • 13,800
  • 10
  • 32
  • 45

2 Answers2

5

You can use the slash at the beginning of the path because is relative to the app/webroot directory:

echo $this->Html->link($this->Html->image('/images/view-more-arrow.png') . ' ' . __('View More'),array('controller' => 'zones', 'action' => 'index'), array('escape' => false));
Marcos
  • 4,643
  • 7
  • 33
  • 60
0

You can also try this, it works perfectly for me.

$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));

Here in $hd, I define the path for the image and then I use this for to make link.

Natalie Hedström
  • 2,607
  • 3
  • 25
  • 36
Amar Prem
  • 35
  • 1
  • 11