CakePHP Absolute URLs

I want to use the $html->image(...) helper function in CakePHP to display images, but I need to create an img tag using an absolute rather than a relative URL (the resulting HTML code will be downloaded and emailed to the News Company mailing list). Is it possible?

This is not documented, but I notice from the source code that the image function can take an array as its first argument. I don’t quite understand how to do this, but a naive attempt to do it this way creates image URLs relative to the current page, and not in the webroot/img folder.

+6
url cakephp
source share
6 answers

In CakePHP 1.x method:

 $this->Html->image($this->Html->url('/path_to_image/image.png',true)); 

In CakePHP 2.x, the method:

 $this->Html->image('/path_to_image/image.png', array('fullBase' => true)); 
+28
source share

The correct way to do this in CakePHP 2.x:

 <?php echo $this->Html->image("logo.png", array('fullBase' => true)); 

Code directly from the cookbook: http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html

+9
source share

$html->image('http://example.com/path_to_image/image.png'); gotta do the trick.

+1
source share

You should be able to use:

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

With the image of the link: -

 <?php echo $this->Html->link($this->Html->image('logo.png',array('alt'=>'Logo')),'/', array('fullBase'=>true)); ?> 

Display only images: -

 <?php echo $this->Html->image('logo.png',array('alt'=>'Logo')),'/', array('fullBase'=>true); ?> 
0
source share

<img src = "http://example.com/path_to_image/image.png" alt = "/">

sometimes it’s better to keep the easiest way

-4
source share

All Articles