2013-05-22 25 views
6

我試圖使用FormHelper..in cakephp鏈接圖像。下面是我的腳本:無法與cakephp 2.x中的鏈接獲取圖像?

<?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 /應用/ Webroot公司/圖像。我不知道爲什麼它採取img /自動。

預先感謝您..

我審閱此鏈接: Cakephp html link with image + text, without using css

+0

謝謝兄弟........我也面臨這個問題。現在我得到了它的解決方案。現在我將用這種方式.... :) – Ayesha

+0

謝謝@enrmarc .....給點建議 – Pank

+0

試試這個回答http://stackoverflow.com/q/13682616/1868660 –

回答

5

您可以在路徑的開始使用斜槓,因爲是相對於應用程序/ webroot的目錄:

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

感謝它爲我工作.. – Pank

+0

謝謝兄弟.....它的工作完美.. – Ayesha

+0

@Ayesha,Pankaj Kumar Jha,很高興幫助 :) –

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,我定義路徑的圖像,然後我用這個做鏈接。