2012-04-07 85 views
2

我有一個電子郵件佈局此代碼段:如何通過Html幫助程序(圖像方法)獲取img標記中圖像的完整鏈接?

<div> 
    <?php echo $this->Html->image('Layouts/default/Logo.png', array(
     'alt' => 'Setin SRL', 
     'url' => $this->Html->url(array('action' => 'index'), true) 
    )); ?> 
    </div> 

然而,這也不行。我可以通過url(array('action' => 'index'), true)

獲取完整URL到網站,但我找不到,我可以設置爲true圖像太任何paramater。任何建議或解決方法,我該如何做到這一點?

編輯1: 基本上,我需要這個鏈接:Layouts/default/Logo.pngIMG SRC

回答

1

成爲http://www.something.com/Layouts/default/Logo.png我總是用

$this->Html->link($this->Html->image(...), $this->Html->url(array('action' => 'index'), true), array('escape'=>false)); 
+0

等等,我的問題是對圖像的引用,而不是鏈接!請參閱我的編輯 – 2012-04-07 19:29:44

+1

這就是我的觀點。你只是不要使用這種方式與URL結合使用圖像(我從來不喜歡它,你可以添加一個URL這種方式在第一位)。 PS:你可以在image()標籤中做同樣的事情:'$ this-> Html-> image($ this-> Html-> url(...,true))' – mark 2012-04-07 19:38:09

+0

是的,但如果我使用* url *方法我錯過了自動鏈接到img目錄(http://mywebsite.something/img/Layouts/default/Logo.png)的可能性,我不得不手動添加它。我知道是愚蠢的,但我沒有使用漂亮的網址功能(主機問題),所以我得到一個http://mywebsite.something/index.php/img/...這不是很好obviusly – 2012-04-07 19:43:07

1

我認爲這是你在找什麼。

​​
+0

雖然我認爲你的回答在邏輯上是正確的,但我認爲蛋糕有一種錯誤,事實上它會輸出:/app/webroot/index.php/Layouts/default/Logo.png 「索引」。 php「obviusly正在創建該問題(請記住,我的重寫mod禁用主機問題) – 2012-04-09 21:46:02

+0

哦,有趣的,你可以嘗試Router :: url('/',true)?那樣有用嗎? – Suman 2012-04-09 21:53:29

+0

「真」我得到了不同的結果,但仍然不好:'http://www.xxx.com.localhost:8080/index.php/Layouts/default/Logo.png「' – 2012-04-09 22:51:50

0
$img = '<img src="http://some-img-link" alt="some-img-alt"/>'; 

$src = preg_match('/<img src=\"(.*?)\">/', $img); 

echo $src; 

我想從img標籤的src價值,也許是ALT值

1

可能是你正在尋找在image方法的實現中使用的HtmlHelper::assetUrl功能:

public function image($path, $options = array()) { 
    $path = $this->assetUrl($path, $options + array('pathPrefix' => Configure::read('App.imageBaseUrl'))); 
    ... 
+0

我相信這是不可用的,當我在這個問題上工作 – 2015-04-23 12:01:40

相關問題