Samson
Samson

Reputation: 2821

Codeigniter configuration file load

I want to use a new file containing constants in Codeigniter so I created the file /config/labels.php

When I try to load it in my controller using $this->config->load('labels'); and it throws application/config/labels.php file does not appear to contain a valid configuration array.

However when I put the code in the constants.php file everything works well.

labels.php 

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

Upvotes: 2

Views: 22460

Answers (4)

Joe Cheng
Joe Cheng

Reputation: 9524

in your config /config/labels.php:

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

in your controller:

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

Upvotes: 0

channasmcs
channasmcs

Reputation: 1156

In the constants file, define a variable like below:

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

Then, in the controller:

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

Upvotes: 2

Prabu Karana
Prabu Karana

Reputation: 302

write in your config example and save as banned_idcard.php

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

And in ur Controoler

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

Upvotes: 0

Broncha
Broncha

Reputation: 3794

The config file should contain an array $config Thats why it throws the error.

When the config class loads the config file, it checks if $config was set. If not it will throw an error.

As far as I know there is no feature to load your own file with custom constants. As of now you will have to add those constants to application/config/constants.php

Upvotes: 8

Related Questions