Failed to get image with link in cakephp 2.x?

I tried to make an image with a link using FormHelper..in cakephp. Following are my scripts:

<?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 path to the image directory is project_folder / app / webroot / images. I do not know why to take it img / automatic.

Thanks at Advance ..

I referred to this link: Cakephp html link with image + text without using css

+6
source share
2 answers

You can use a slash at the beginning of the path because it 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)); 
+5
source

You can also try this, it works great 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 to create the link.

0
source

Source: https://habr.com/ru/post/945562/


All Articles