我如何在cakephp 3.1中获得完整的相对路径?

时间:2017-06-13 18:13:42

标签: php html image cakephp

我想发送带有图片的电子邮件,图片必须是完整路径, 就像,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">但这不是正确的方式。

请以示例的方式提出正确的方法。

由于 麦。

1 个答案:

答案 0 :(得分: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框架建议的正确方法。

相关问题