Integrate CakePHP with Medianova CDN
Learn how to integrate CakePHP with Medianova CDN to deliver static assets such as images, CSS, and JavaScript files faster and improve website performance.
CakePHP is an open-source PHP framework based on the MVC (Model-View-Controller) pattern, similar to Zend, Laravel, and Symfony. This guide explains how to configure Medianova CDN for CakePHP version 2.4 and later, enabling your application to serve static content from the nearest CDN edge node instead of the origin server.
Prerequisites
A configured CDN Resource.
A running CakePHP 2.4+ application
Write access to your
./Config/bootstrap.phpfile
Integration Steps
Create a CDN Resource
Log in to the Medianova Control Panel.
Create a new CDN Resource for your application.
Copy your Resource URL (for example:
https://example.mncdn.com/).
Define CDN Base URLs
Open the configuration file: &#xNAN;
./Config/bootstrap.phpAdd the following variables to define Medianova CDN paths for your assets:
<?php
Configure::write('App.imageBaseUrl', 'https://<CDN_ZONE_URL>/img/');
Configure::write('App.cssBaseUrl', 'https://<CDN_ZONE_URL>/css/');
Configure::write('App.jsBaseUrl', 'https://<CDN_ZONE_URL>/js/');Use the HTML Helper for Images
Use the HtmlHelper::image() function to generate image URLs automatically through the CDN.
<?php echo $this->Html->image('medianova-logo.png', ['alt' => 'Medianova Logo']); ?>Output:
<img src="https://example.mncdn.com/img/medianova-logo.png" alt="Medianova Logo" />Use the HTML Helper for CSS Files
To load your CSS files from the CDN, use the HtmlHelper::css() function:
<?php echo $this->Html->css('style.css'); ?>Output:
<link rel="stylesheet" type="text/css" href="https://example.mncdn.com/css/style.css" />Use the HTML Helper for JavaScript Files
To load JavaScript assets from the CDN, use the HtmlHelper::script() function:
<?php echo $this->Html->script('script.js'); ?>Output:
<script type="text/javascript" src="https://example.mncdn.com/js/script.js"></script>Verify Integration
Save your configuration and clear the CakePHP cache.
Open your website in a browser and view the HTML source (
Ctrl + U).Confirm that image, CSS, and JS assets are loaded from your Medianova CDN Resource.
Troubleshooting
Assets still load from the origin server
CDN URLs not defined or configuration not reloaded.
Check the bootstrap.php entries and clear the CakePHP cache.
Assets missing or 404 errors
Incorrect CDN path or directory mismatch.
Verify that your img, css, and js directories match the structure in your CDN Resource.
Mixed content warning (HTTP/HTTPS)
HTTPS not enabled on CDN resource.
Enable Shared SSL or Custom SSL in the Medianova Control Panel before using secure URLs.
Last updated
Was this helpful?