1

I am trying to load a custom config in codeigniter 3

$this->config->load('test')

test.php file is available in application/config folder with following content.

<?php

$config['item_test']='sample config item';

I will get the following error

The configuration file test.php does not exist.

Codeigniter version:3.1.0

1 Answer 1

5

Create new file name test.php in application/config folder.

  • application/config/test.php

    <?php
        $config['gender'] = array('Male', 'Female');
    ?>
    
  • controllers/filename.php

        class Stackoverflow extends CI_Controller{
            function __construct() {
                parent::__construct();
    
                $this->config->load('test'); //loading of config file
            }
    
            function index(){
    
                print_r($this->config->item('gender')); //Calling of config element.      
        }
    }
    
  • Output

    Array ( [0] => Male [1] => Female )

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.