Custom config file for codeigniter

Viewed 46731

Very new to CodeIgniter, trying to create a custom config file to load special variables into my application.

in application/config/ I created custom.php and placed the following code in that file:

<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

$gender = array ('male','female'); 

?>

I then opened up application/config/autoload and altered the following code:

$autoload['config'] = array();

/* TO: */ 

$autoload['config'] = array('custom');

I refresh my application and see this error:

Your application/config/custom.php file does not appear to contain a valid configuration array.

I opened up some of the default config files and don't see a configuration array? What am I doing wrong?

3 Answers

CodeIgniter 3

Step 1: Create the custom configuration file

/path/to/codeigniter/application/config/custom.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

$config['server'] = array (
    'host'      => 'example.com',
    'public_ip' => '93.184.216.34'
    );
?>

Step 2: Load the custom configuration file

This can be done either inside a model or a controller.

// load the configuration file
$this->config->load('custom');

// retrieve the content of a specific configuration
$server = $this->config->item('server');

// $server is now set
echo $server['host']; // example.com
Related