How do I get the full URL to an image in Cakephp?
cakephp, hyperlink, image, path, url
Solution
After trying the various CakePHP global constants (ROOT, WEBROOT_DIR, WWW_ROOT, CSS, etc.) with no results, the general solution seems to be found in the $this->webroot property that returns the path to the application webroot. Thus for the various cases above we may have in our layouts, views or elements:
A simple image tag:
<img src="<?php echo $this->webroot; ?>img/foo.gif" .../ >
A background image within a table cell the old way:
<td background="<?php echo $this->webroot; ?>img/foo.gif">
An input of type="image":
<input type="image" src="<?php echo $this->webroot; ?>img/go_btn.gif" ... />
I think webroot always work
Problem
Let's say I have an "image.jpg" stored in the assets folder and the path is "www.example.com/public" and I want only the string path to the image. How do I get this? I do NOT want the html tags only the path string.