[英]How i can get full relative path of image in cakephp 3.1?
我想發送帶有圖像的電子郵件,並且圖像必須具有完整的路徑,例如http://www.example.com/img/image-name.jpg因此,我正在使用帶有代碼的cakephp 3框架:
$this->Html->image('image.jpg', ['fullBase' => true]);
錯誤提示: Path is not found
我認為webroot總是可以正常工作: <img src="<?php echo $this->webroot; ?>img/image-name.jpg">
但這不是正確的方法。
請舉例說明正確的方法。
謝謝麥
對於電子郵件發送,您必須具有圖像的完整路徑,
`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框架建議的正確方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.