Ethan Ethan - 18 days ago 5
PHP Question

Creating Config File for Custom Library in CodeIgniter

I've looked through all of the CI documentation, and done some Googling of it, but I still can't quite seem to figure out how to create a configuration file for a custom library in codeigniter. If somebody could even just point me in the direction of where in the docs I could find my answer it would be greatly appreciated.

I am creating a library in CI that makes use of several database columns that can vary in name between applications, so I would like the names to be stored in a custom config file. Then I would like to be able to load these values in the construct of the library.

So my two questions are:

1.) How do I name the config file, and how do I name variables within that file so they don't overwrite any other config vars?

2.) How do I get the values from within my library?

Answer

When i have questions like this i like to look at other projects that already do this. We utilized Tank_auth in almost all of our ci projects. This is a popular authentication library, which has its own custome config files

  1. It just creates its own config file in application/config directory. You could prefix your config items with your app name to ensure that they are unique

  2. it then just loads it in the constructor:

    $this->ci->load->config('tank_auth', TRUE);