我想使用 $html->image(...)
CakePHP 中的辅助函数用于输出图像,但我需要它来生成 img
使用绝对而不是相对 URL 标记(生成的 HTML 将被下载并通过电子邮件发送到公司通讯中)。这可能吗?
它没有记录,但我从查看源代码中注意到 image
函数可以将数组作为其第一个参数。我并不完全清楚如何让这个工作 - 一个天真的尝试这样做会产生相对于当前页面而不是在 webroot/img
内的图像 URL。文件夹。
最佳答案
在 CakePHP 1.x 中,方法是:
$this->Html->image($this->Html->url('/path_to_image/image.png',true));
在 CakePHP 2.x 中,方法是:
$this->Html->image('/path_to_image/image.png', array('fullBase' => true));
关于url - CakePHP 绝对图像 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1038877/