php - Codeigniter - Failing to load config

609

In my code, According to the user guide, I write this code (In a controller)

$this->config->load('countries_config.php');

But unfortunately, get this PHP error:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Countries::$config

Filename: controllers/Countries.php

Line Number: 12

Any idea why I can't use the config?

Countries extendsCI_Controller

864

Answer

Solution:

To load one of your custom config files you will use the following function within the controller that needs it:

$this->config->load('filename');

Where filename is the name of your config file, without the .php file extension.

without .php extensions

try this

$this->config->load('countries_config');
471

Answer

Solution:

what is counteries_config.php is this controller,model or view file $this->config->load('filename');

859

Answer

Solution:

OK, the problem occured because I was trying to load the config file before doingparent::_construct();

Fixed by doing it after

People are also looking for solutions to the problem: php - Select2 dropdown with dynamic name and image in yii2

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.