正在加载自定义配置文件codeigniter 3


Loading custom config file codeigniter 3

我正在尝试在codeigniter 3 中加载自定义配置

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

test.php文件位于application/config文件夹中,包含以下内容。

<?php
$config['item_test']='sample config item';

我将得到以下错误

配置文件test.php不存在。

Codeigniter版本:3.1.0

在application/config文件夹中创建新文件名test.php。

  • application/config/test.php

    <?php
        $config['gender'] = array('Male', 'Female');
    ?>
    
  • 控制器/文件名.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.      
        }
    }
    
  • 输出

    阵列([0]=>阳性[1]=>阴性)