Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom config file for codeigniter

Tags:

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?

like image 273
Mitch Evans Avatar asked Dec 28 '13 04:12

Mitch Evans


People also ask

How to change config file in CodeIgniter?

with this: $this->config->set_item('item_name', 'item_value'); you can change your config item on the fly.

Where is CodeIgniter config file?

By default, CodeIgniter has one primary config file, located at application/config/config. php. If you open the file using your text editor you'll see that config items are stored in an array called $config.


1 Answers

Use

$config['gender']= array ('male','female'); 

instead of

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

For fetching config item

$this->config->item('item_name'); 

Where item_name is the $config array index you want to retrieve.

Docs : CodeIgniter User Guide 2.x CodeIgniter User Guide 3.x

like image 150
Pranav C Balan Avatar answered Oct 02 '22 16:10

Pranav C Balan