代码点火器配置文件加载


Codeigniter configuration file load

我想在Codeigniter中使用一个包含常量的新文件,所以我创建了文件/config/labels.php

当我尝试使用 $this->config->load('labels'); 将其加载到我的控制器中时,它会抛出 application/config/labels.php file does not appear to contain a valid configuration array.

但是,当我将代码放入常量.php文件中时,一切正常。

labels.php 
<?php
define('CLI_CIVILITE','Civilité');
define('CLI_NOM','Nom');
define('CLI_PRENOM','Prenom');

配置文件应包含一个数组$config这就是它抛出错误的原因。

当 config 类加载配置文件时,它会检查是否设置了$config。如果不是,它将抛出错误。

据我所知,没有使用自定义常量加载您自己的文件的功能。截至目前,您必须将这些常量添加到application/config/constants.php

在常量文件中,定义一个变量,如下所示:

$ORDER_STATUS = array(
    '0' => 'In Progress',
    '1' => 'On Hold',
    '2' => 'Awaiting Review',
    '3' => 'Completed',
    '4' => 'Refund Requested',
    '5' => 'Refunded');

然后,在控制器中:

function __construct()
{
    $this->config->load('$ORDER_STATUS');
}

编写配置示例并另存为banned_idcard.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config ['banned_idcard'] = array (
'23104013',
'2010201103',
'11106062',
);

在你的争议中

<?php
function __construct () {
$banned_idcards = $this->config->load('banned_idcard');
}
在你的

配置/config/labels.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config = array(
    'CLI_CIVILITE' => 'Civilité',
    'CLI_NOM' => 'Nom',
    'CLI_PRENOM' => 'Prenom'
);

在控制器中:

$this->config->load('labels');
var_dump((array)$this->config); //show all the configs including those in the labels.php