2009-06-24 73 views
6

我希望在CakePHP中使用$html->image(...)辅助函数来输出图像,但我需要它使用绝对而不是相对URL生成img标记(将生成的HTML下载并通过电子邮件发送到公司通讯)。这可能吗?CakePHP绝对图像URL

这是没有记录,但我注意到从源代码image函数可以采取一个数组作为其第一个参数。我不完全清楚如何实现这个目标 - 虽然这样做的天真尝试会产生相对于当前页面的图像URL,而不是在webroot/img文件夹中。

回答

28

在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)); 
+1

+1仅用于实际便携式解决方案。 – deizel 2011-08-10 14:53:51

1

$html->image('http://example.com/path_to_image/image.png');应该做的伎俩。

+3

这应该是CakePHP的座右铭:) – 2009-06-25 13:22:05

+1

如果我将我的网站是在example2.com? – Matthew 2014-02-04 16:47:33

-4

< IMG SRC = “http://example.com/path_to_image/image.png” ALT = “”/>

有时最好是保持简单的方法

+0

在Cake的情况下,它明显不是。 – 2013-08-06 17:25:28

0

你应该能够使用方法:

$html->image('http://[domain]/[path]/[image]') 
0

随着链接图片: -

<?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); ?>