Codeigniter 4 Load settings from database |
I would like to load few settings that is previously stored in Database (e.g. site language, site name etc.) and those settings will be used everywhere in the application. Previously in Codeigniter 3 I've done this by adding below code in application/config/config.php file.
Code: require_once(BASEPATH . 'database/DB.php'); But I'm bit confused about to Codeigniter 4 where or in which file I should put this code to get expected result. Any suggestion?
In CI 4 that would be app/Config/app.php
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
You can create your own configuration file and this file may contain any properties and methods as you want. You can use it in your application wherever - just load it with namespase as usual config class.
After several attempts I got the way to overcome this issue.
First need to create a Custom Config file in App/Config directory. Let’s say my Custom Config name is MyConfig.php Code: <?php namespace Config; Now It can be used in any Controller or anywhere. Example: $myconfig = config('MyConfig');
@Hemil you may want to check out Tatter\Settings which manages exactly this in a separate service: https://github.com/tattersoftware/codeigniter4-settings
Your implementation might look something like this... Setup: Code: 1. Install with Composer: > composer require tatter/settings Using it: PHP Code: // Load the service |
Welcome Guest, Not a member yet? Register Sign In |