We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Sub domain

Hello ,

how can i create a subdomain for Phalcon so i could use it as an external lik for my images ? example :

images are stored in assets/public/posts/images/

and i want to be able to generate an external link like : https://graphic.mydomain.com/image_name and NOT access via normal url, example: https://mydomain.com/assets/public/posts/images/image_name

Hi hudson you can make a user component to do that


    class ExternalUrl extends \Phalcon\Mvc\User\Component {
        public function getUrl(string $image) : string 
        {
            return 'https://graphic.mydomain.com/' . ltrim($image, '/');
        }
    }

Then you have to include this in your Di and use everywhere



43.9k

Hi,

How do you generate your image html tag.

If you're using phalcon tag component (like {{ image("https://static.mywebsite.com/img/bg.png", false) }} ) you can extend it to always use https://static.mywebsite.com/img/ as a default prefix.

You can also check our website implementation here: https://github.com/phalcon/website/

In the Utils class we have a function called getAsset (https://github.com/phalcon/website/blob/master/app/library/Utils.php#L65). This function will return a URL for an asset (CSS/JS) based on what you define in your configuration's staticUrl

If you are in development mode, staticUrl is /. In production mode you can replace it with https://static.mydomain.com/ and that will be prefixed to all of your assets.

Note that in the website implementation we are using the Phalcon Assets Manager to generate our asset links so if you want to use that, you will also need to define in the addCss and addJs functions whether the resource is local or not. This is what this fuction is about:

https://github.com/phalcon/website/blob/master/app/library/Utils.php#L102

and the implementation (with assets manager) is here:

https://github.com/phalcon/website/blob/master/app/library/Bootstrap/AbstractBootstrap.php#L87