Reputation: 135
I'm trying to append CDN url to all image resources across the site.
current code looks like this $this->Html->image('img.png')
. I found that there's an option to append baseURL ['fullBase' => true]
, but I couldn't find an option to append custom URL that would route to desired CDN. Is there a way to create a custom setting that would point to CDN url such as ['CDN_URL_1' => true]
or any other clean way to achieve this?
The other approach I can think about is appending path like so $this->Html->image($customURL.'img.png')
, but this might not be the correct approach.
Thanks!
Upvotes: 0
Views: 140
Reputation: 14967
You can define the base URL for those items in your config file (./Config/bootstrap.php
).
See Configuration.
App.imageBaseUrl
Web path to the public images directory under webroot. If you are using a CDN you should set this value to the CDN’s location.
App.cssBaseUrl
Web path to the public css directory under webroot. If you are using a CDN you should set this value to the CDN’s location.
App.jsBaseUrl
Web path to the public js directory under webroot. If you are using a CDN you should set this value to the CDN’s location.
...
Configure::write('App.imageBaseUrl', 'http://yourcdn.com/img/');
Configure::write('App.jsBaseUrl', 'http://yourcdn.com/js/');
Configure::write('App.cssBaseUrl', 'http://yourcdn.com/css/');
...
Then just use $this->Html->image('img.png')
normally.
Upvotes: 2