CodeIgniter Forums
Public variable - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Public variable (/showthread.php?tid=73139)



Public variable - edica - 03-22-2019

Codeigniter 3 I had in /config/config.php:

$config['cdn_url']  = 'https://domain.com/';

But Codeigniter 4 it does not work this way:

public $cdn_url  = 'https://domain.com/';


RE: Public variable - MGatner - 03-22-2019

You can still use configuration files very much the same way that CI3 used to do them... Check out the user guide if you haven't already: https://codeigniter4.github.io/CodeIgniter4/general/configuration.html
It probably mostly comes down to what you want to be doing with that variable.


RE: Public variable - edica - 03-22-2019

Anyway, the goal is to do this below for Codeigniter 4. It's hard. Can anyone help?

https://www.keycdn.com/support/codeigniter-cdn-integration


RE: Public variable - MGatner - 03-22-2019

That's a whole lot of work for a relatively simple result. If you are using an application that already includes all its assets using `base_url()` then it might save a little time by extending the URL Helper to override `base_url()`... but if you are writing new, or don't have that many calls to `base_url()` I'd recommend just doing this yourself. You could make a simple keycdn helper:
PHP Code:
if (! function_exists('keycdn'))
{
    function 
keycdn(string $uri ''): string
    
{
        return 
'https://examplepull-1a2b.kxcdn.com/' $uri;
    }


Then in your view just call that instead of `base_url()` anytime you want to use a CDN asset: `<?= keycdn('styles.css') ?>`


RE: Public variable - edica - 03-23-2019

It worked.. Thank you for the help. Smile


RE: Public variable - titounnes - 03-24-2019

(03-22-2019, 12:01 PM)edica Wrote: Anyway, the goal is to do this below for Codeigniter 4. It's hard. Can anyone help?

https://www.keycdn.com/support/codeigniter-cdn-integration
you can call your config:
echo Config('ConfigName')->property
for example
echo Config('App')->cdn_url