views:

26

answers:

2

Hi. My CakePHP Folder Structure

   1. app / webroot / img
   2. cake
   3. vendors
   4. assets

<?php echo $html->image('cake_logo.png', array('alt' => 'CakePHP'))?>

Is it possible to access my external asset directory with the CakePHP Image helper?

A: 

I've never tried this, but I believe that Cake relies on the web server to serve up image assets by default. This would suggest that, no, you can't move your images outside of your web root and still use the HTML helper's image() method.

You can, however, use media views to send binary information to users. It works outside of the core helpers, but might meet your needs.

Rob Wilkerson
I added a RedirectMatch rule to the .htaccess in the webroot directory.RedirectMatch /img/(.*) http://assets.example.com/img/$1
Juri
Hey, you added a _new_ web root. That's cheating. :-)
Rob Wilkerson
A: 

Try to go up the directory by adding ../ at the front of image file as many times as it is necessary like this:

echo $html->image('../../special_assets_folder/cake_logo.png');

That worked for me in some cases.

bancer
No, that won't work. The Cake Image helper will output this: <img src="/img/../../special_assets_folder/cake_logo.png" />
Juri
What about `echo $html->image('/../../special_assets_folder/cake_logo.png');`? Notice - starting with slash.
bancer