# Integrate Phalcon with Medianova CDN

Phalcon is an open-source PHP framework designed for speed and efficiency.\
Unlike traditional PHP frameworks, Phalcon is implemented as a C extension, providing exceptional execution performance with MVC architecture support.

This guide explains multiple integration methods for connecting Phalcon-based applications with **Medianova CDN** to deliver static files (CSS, JS, images) from the nearest CDN edge.

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

### Prerequisites

* A configured **CDN Resource**
* Access to the Phalcon project source code
* PHP 7.4 or later (recommended)

### Integration Methods

{% stepper %}
{% step %}
**Use `setStaticBaseUri`**

The simplest way to integrate your Phalcon application with Medianova CDN is by defining a static base URI.\
This approach ensures that dynamic content stays on your origin, while static files (CSS, JS, images) are delivered via CDN.

```php
<?php

$url = new Phalcon\Mvc\Url();

// Dynamic URIs remain on your origin server
$url->setBaseUri('/');

// Static resources go through Medianova CDN
$url->setStaticBaseUri('https://<CDN_ZONE_URL>/');

```

{% hint style="info" %}
Replace `<CDN_Resource_URL>` with your actual CDN Resource URL (for example: `https://example.mncdn.com/`).
{% endhint %}
{% endstep %}

{% step %}
**Use Asset Collections with Conditional CDN Prefix**

For more granular control, you can configure your asset collections to automatically switch between development and production environments.

```php
<?php

$css = $this->assets->collection('header');
$scripts = $this->assets->collection('footer');

if ($config->environment == 'development') {
    $css->setPrefix('/');
    $scripts->setPrefix('/');
} else {
    $cdnURL = 'https://<CDN_ZONE_URL>/';
    $css->setPrefix($cdnURL);
    $scripts->setPrefix($cdnURL);
}

$css->addCss('css/bootstrap.min.css')
    ->addCss('css/custom.css');

$scripts->addJs('js/jquery.js')
    ->addJs('js/bootstrap.min.js');

```

{% hint style="info" %}
This method allows you to automatically use local assets in development and CDN-prefixed URLs in production.
{% endhint %}
{% endstep %}

{% step %}
**Direct CDN Path in Asset Definition**

You can also directly define CDN-prefixed URLs when adding assets to your project.

```php
<?php
$cdnURL = 'https://<CDN_ZONE_URL>/';
$this->assets
     ->addCss($cdnURL . 'css/custom.css', false);
```

{% endstep %}

{% step %}
**Verify CDN Integration**

After applying one of the methods above:

1. Deploy your changes to the web server.
2. Open your website in a browser.
3. View the HTML source (`Ctrl + U`) and confirm that static file URLs begin with your **CDN Resource** domain.

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

### Troubleshooting

| Problem                                     | Cause                                                     | Solution                                                                                                                           |
| ------------------------------------------- | --------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| **Assets are still served from the origin** | The CDN prefix is not applied in code.                    | Verify that `setStaticBaseUri()` or `$css->setPrefix()` includes your correct CDN Resource URL.                                    |
| **Invalid asset paths**                     | The CDN prefix or local directory structure is incorrect. | Check the path structure inside your assets directory and ensure the CDN path matches the file hierarchy.                          |
| **SSL-related warnings**                    | HTTPS not enabled on CDN resource.                        | Enable **Shared SSL** or **Custom SSL** in the [**Medianova Control Panel**](https://cloud.medianova.com) before using HTTPS 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/phalcon-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.
