2017-06-13 24 views
0

我想與圖片發送電子郵件,並且圖像有必須的完整路徑, 一樣,http://www.example.com/img/image-name.jpg 所以,我使用CakePHP 3框架,代碼:如何在cakephp 3.1中獲得完整的圖像相對路徑?

$this->Html->image('image.jpg', ['fullBase' => true]);

錯誤accurs:Path is not found

我覺得webroot總是可以工作的:<img src="<?php echo $this->webroot; ?>img/image-name.jpg">但是這不是正確的方法。

請用實例說明正確的方法。

謝謝 Mak。

+1

您_think_使用'webroot'的作品?你真的嘗試過了嗎?此外,錯誤發生在哪裏,它不會像CakePHP錯誤那樣讀取?並且'image()'調用返回的是_exactly_? – ndm

+1

我想使用fullpath進行圖像處理,所以來自其他服務器的電子郵件可以讀取圖像,我已經嘗試使用上面提到的代碼,但是代碼不會生成整個頁面:' ,你有什麼想法我如何管理電子郵件? –

+0

我有點感覺到,但是你沒有回答我的任何問題。 – ndm

回答

1

對於電子郵件發送,您必須對圖像的完整路徑,

`echo $this->Html->image("recipes/6.jpg", [ 
    "alt" => "Brownies", 
    'url' => ['controller' => 'Recipes', 'action' => 'view', 6] 
]);` 

將輸出:

`<a href="/recipes/view/6"> 
    <img src="/img/recipes/6.jpg" alt="Brownies" /> 
</a>` 

但是,你必須使用,

echo $this->Html->image("logo.png", ['fullBase' => true]);

將輸出:

<img src="http://example.com/img/logo.jpg" alt="" />

https://book.cakephp.org/3.0/en/views/helpers/html.html#linking-to-images

這是建議的CakePHP的框架之有道。

+1

謝謝你的回答。是的,它爲我工作。 –

相關問題