# Integrate CakePHP with Medianova CDN

**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.

{% hint style="info" %}
Before starting the integration, back up your CakePHP project files and database.
{% endhint %}

### Prerequisites

* A configured **CDN Resource**.
* A running **CakePHP 2.4+** application
* Write access to your `./Config/bootstrap.php` file

### Integration Steps

{% stepper %}
{% step %}
**Create a CDN Resource**

* Log in to the [**Medianova Control Panel**](https://cloud.medianova.com).
* Create a new **CDN Resource** for your application.
* Copy your Resource URL (for example: `https://example.mncdn.com/`).
  {% endstep %}

{% step %}
**Define CDN Base URLs**

* Open the configuration file:\
  \&#xNAN;**`./Config/bootstrap.php`**
* Add the following variables to define Medianova CDN paths for your assets:

```php
<?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/');
```

{% hint style="info" %}
Replace `<CDN_RESOURCE_URL>` with your actual CDN Resource address, such as `https://example.mncdn.com/`.
{% endhint %}
{% endstep %}

{% step %}
**Use the HTML Helper for Images**

Use the `HtmlHelper::image()` function to generate image URLs automatically through the CDN.

```php
<?php echo $this->Html->image('medianova-logo.png', ['alt' => 'Medianova Logo']); ?>
```

**Output:**

```html
<img src="https://example.mncdn.com/img/medianova-logo.png" alt="Medianova Logo" />
```

{% endstep %}

{% step %}
**Use the HTML Helper for CSS Files**

To load your CSS files from the CDN, use the `HtmlHelper::css()` function:

```php
<?php echo $this->Html->css('style.css'); ?>
```

**Output:**

```html
<link rel="stylesheet" type="text/css" href="https://example.mncdn.com/css/style.css" />
```

{% endstep %}

{% step %}
**Use the HTML Helper for JavaScript Files**

To load JavaScript assets from the CDN, use the `HtmlHelper::script()` function:

```php
<?php echo $this->Html->script('script.js'); ?>
```

**Output:**

```html
<script type="text/javascript" src="https://example.mncdn.com/js/script.js"></script>
```

{% endstep %}

{% step %}
**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**.

{% hint style="info" %}
Example:\
`https://example.mncdn.com/css/style.css`
{% endhint %}
{% endstep %}
{% endstepper %}

### Troubleshooting

| Problem                                      | Cause                                               | Solution                                                                                             |
| -------------------------------------------- | --------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| **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. |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://clients.medianova.com/products/performance-cdn/static-content-delivery/website-framework-integrations/cakephp-cdn-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
