我希望在CakePHP中使用$html->image(...)
辅助函数来输出图像,但我需要它使用绝对而不是相对URL生成img
标记(将生成的HTML下载并通过电子邮件发送到公司通讯)。这可能吗?CakePHP绝对图像URL
这是没有记录,但我注意到从源代码image
函数可以采取一个数组作为其第一个参数。我不完全清楚如何实现这个目标 - 虽然这样做的天真尝试会产生相对于当前页面的图像URL,而不是在webroot/img
文件夹中。
我希望在CakePHP中使用$html->image(...)
辅助函数来输出图像,但我需要它使用绝对而不是相对URL生成img
标记(将生成的HTML下载并通过电子邮件发送到公司通讯)。这可能吗?CakePHP绝对图像URL
这是没有记录,但我注意到从源代码image
函数可以采取一个数组作为其第一个参数。我不完全清楚如何实现这个目标 - 虽然这样做的天真尝试会产生相对于当前页面的图像URL,而不是在webroot/img
文件夹中。
在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));
$html->image('http://example.com/path_to_image/image.png');
应该做的伎俩。
这应该是CakePHP的座右铭:) – 2009-06-25 13:22:05
如果我将我的网站是在example2.com? – Matthew 2014-02-04 16:47:33
< IMG SRC = “http://example.com/path_to_image/image.png” ALT = “”/>
有时最好是保持简单的方法
在Cake的情况下,它明显不是。 – 2013-08-06 17:25:28
你应该能够使用方法:
$html->image('http://[domain]/[path]/[image]')
正确的方式做,这是一个在CakePHP 2.X:
<?php
echo $this->Html->image("logo.png", array('fullBase' => true));
代码被拉离菜谱直接: http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html
随着链接图片: -
<?php echo $this->Html->link($this->Html->image('logo.png',array('alt'=>'Logo')),'/', array('fullBase'=>true)); ?>
个仅适用于图像显示: -
<?php echo $this->Html->image('logo.png',array('alt'=>'Logo')),'/', array('fullBase'=>true); ?>
+1仅用于实际便携式解决方案。 – deizel 2011-08-10 14:53:51