CodeIgniter Forums
Load custom config file? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Load custom config file? (/thread-76057.html)



Load custom config file? - vinyl - 04-11-2020

I made a custom config file with some general settings I want to access in my controllers.

When I make a new controller and load the config file I can access the variables I set:

Code:
$customvalues = new \Config\Custom();
echo $customvalues->myvalue;

How can I load the config file so that I dont have to initiate a new instance in every class of the controller but like in codeigniter 3 one would do in a constructor function?


RE: Load custom config file? - includebeer - 04-12-2020

You can load it in the base controller. It would be available for all your controllers. You can also get a shared instance with the config() function like described on this page of the user guide: https://codeigniter4.github.io/userguide/general/configuration.html#accessing-config-files


RE: Load custom config file? - InsiteFX - 04-12-2020

Or you can load in the Common.php file.