It's a great idea to have configuration settings in the same file—the benefits are obvious—so rather than having settings hidden in controllers, modules, helpers, libraries, or (God forbid) in views, you can put them in one location and refer to them from there. CodeIgniter comes with its own configuration files in the config
folder; however, you can add your own files to the config
folder and refer to them in your code. It's pretty handy and easy to do; let's take a look.
We're going to create the following two files:
/path/to/codeigniter/application/controllers/config_settings.php
/path/to/codeigniter/application/config/my_config_file.php
Create the
config_settings.php
controller, open it for editing, and add the following code to it:<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Config_settings extends CI_Controller { function __construct() { parent::__construct(); ...