【问题标题】:How i can get full relative path of image in cakephp 3.1?我如何在 cakephp 3.1 中获得图像的完整相对路径?
【发布时间】:2017-06-15 02:18:13
【问题描述】:

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

请举例说明正确的方法。

谢谢 马克。

【问题讨论】:

  • 认为使用webroot 有效吗?你真的试过了吗?此外,该错误发生在哪里,它不像 CakePHP 错误那样读取? image() 调用返回的究竟是什么
  • 我想用完整路径进行图像,所以我从其他服务器发送的电子邮件可以读取图像,我已经尝试使用上述代码,但代码无法生成完整页面:<image src="img/image.jpg" class="" >,你知道我怎么能管理电子邮件?
  • 我有点感觉到,但是你没有回答我的任何问题。
  • 当我使用<img src="<?php echo $this->webroot; ?>img/image-name.jpg">时,它会生成相同的<image src="img/image.jpg">,当我在本地机器上调试电子邮件模板时,图像和所有其他内容都能正常显示,但在实际的电子邮件图像中不显示。

标签: php html image cakephp


【解决方案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-&gt;Html-&gt;image("logo.png", ['fullBase' =&gt; true]);

将输出:

&lt;img src="http://example.com/img/logo.jpg" alt="" /&gt;

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

这是 CakePhp 框架建议的正确方式。

【讨论】:

    猜你喜欢
    • 2011-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-06
    • 2014-07-30
    • 2019-08-10
    • 1970-01-01
    相关资源
    最近更新 更多