Welcome Guest, Not a member yet? Register   Sign In
Config File not loading - Double loading Config File
#1

[eluser]Unknown[/eluser]
I eventually solved this problem, but felt I should share my pain and solution in case it helps someone else.

During development I found that a variables from a custom config file were sometimes correct and sometimes null. This would change depending on the method despite exactly the same code. Having had previous pain with naming conventions, I copied / renamed the config file which initially solved the problem although after changing throughout my code the problem returned.

What I did wrong:

In one library method I loaded the config file and assigned it to an index as so:

$this->config->load('my_config', TRUE);

Subsequent attempts to load the library without an index then fail to load (to avoid loading the config twice). And then requests for un-indexed items are returned as NULL.

Anyone think a little warning should be put in the manual for this? I would have thought default behaviour would be to prevent re-loading based on filename and index even though I cant immediately think of GOOD reasons to load into multiple indexes.
#2

[eluser]Cristian Gilè[/eluser]
Hi guiriverde,

from the guide:

Quote:To access CodeIgniter's native resources within your library use the get_instance() function. This function returns the CodeIgniter super object.

Code:
class Superclass
{
    protected $CI;

    function __construct()
    {
        $this->CI =& get_instance();
    }

    function some_function()
    {
        $this->CI->load->config('my_config',TRUE);
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB