Welcome Guest, Not a member yet? Register   Sign In
Lifecycle init to render. Where can I place an INI file?
#1

I'd like to add an ini based configuration to my setup, that is accessible to the files in the config folder, but at a level within the app that doesn't require me to go into each file and manually add the command to parse the ini over and over since thats redundant overhead I dont want.

The main purpose to this file is so I can store various settings such as db credentials for different environments, ie development, stage, beta, production... as well as other various configurations but keep them locked down in such as way only those who need to know them will know them as such would be the case with the production environment.

So the overall question is where can I place an INI file into the mix as its loading that will be accessible to all that gets loaded including the stuff in the conf folder. I am looking for something above controller, and the hooks to them.
Reply
#2

Store it in your application config folder.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

Codeigniter addresses this ability by way of the config library.
Read all about it.
Reply
#4

(09-20-2016, 07:20 AM)dave friend Wrote: Codeigniter addresses this ability by way of the config library.
Read all about it.

Yes, yes I could. However the primary reason for my post is so I can create a single source of truth, that those specific files you point me towards can make use of, so I don't have to create an ignore rule in my code versioning repository to ignore the whole config folder or specific files therein. I feel this is to much overhead in the long run, and can easily be forgotten in time, and when it comes time to upgrade can easily be lost. Where as a single source of truth included at a level accessible by those same configuration files can serve a greater purpose in having various environments for development, testing, and production.

But in all this I realize that no one likely knows a good answer, so I may have to go the higher overhead route. I just prefer the lessor.
Reply
#5

I must not clearly understand what you want to achieve. Codeigniter already provides a "single point of truth" for configuration in the form of a server variable - $_SERVER['CI_ENV']. See the documentation on  Handling Multiple Environments.

Because CI will configure error reporting based on the value of $_SERVER['CI_ENV'] you must do one of the following to assure that error reporting is appropriate:
  1. Explicitly set the value of $_SERVER['CI_ENV']. (Available options are "development", "testing", "production".)
  2. Edit index.php so that the ENVIRONMENT constant is set to the appropriate value. (The default value is "development" in the distribution version of index.php.)
  3. Reinvent the wheel and write your own code to set the error reporting level.
Item 1 seems the easiest and least fragile answer to me. You probably don't want error reporting full-on in a production environment and using the server var makes it easy to assure it is set appropriately.

Items 2 is very fragile when it comes to upgrading the CI framework because it can be easily missed.

Item 3 might be fragile depending on exactly where/how it is implemented.

The ENVIRONMENT constant is also the key to loading different sets of config items. Take a close look at the Config Class documentation in the section Environments. Look very closely at the Note at the bottom of that section.

Understanding that note is key to populating the various folders with only the files and config items related to any given environment.

It is a very low overhead solution that allows complete control over environment-based configuration without having to invent something new.

Setting a ignore folder rule for a repository's distribution branch seems a small price to pay compared to reinventing the wheel.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB