CodeIgniter Forums
Bug in System->Libraries->Config.php - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Bug in System->Libraries->Config.php (/showthread.php?tid=10028)



Bug in System->Libraries->Config.php - El Forum - 07-16-2008

[eluser]ErwinVanHoof[/eluser]
When using custom Config files I came across the following error:

Using:
Code:
$this->config->load('[config_filename]', TRUE);

I was unable to retrieve the values with the function:
Code:
$this->config->item('[config_filename]','[item]')

The problem is caused by the function item() in Config.php.
In the else statement the function first looks at index and not the item which should be the other way around, the same fault is repeaeted in the function.

The problems is solved by changing:
-system
-libraries
Config.php

starting at line 124:
Code:
function item($item, $index = '')
    {    
        if ($index == '')
        {    
            if ( ! isset($this->config[$item]))
            {
                return FALSE;
            }

            $pref = $this->config[$item];
        }
        else
        {
            if ( ! isset($this->config[$index]))
            {
                return FALSE;
            }

            if ( ! isset($this->config[$index][$item]))
            {
                return FALSE;
            }

            $pref = $this->config[$index][$item];
        }

        return $pref;
    }
to
Code:
function item($item, $index = '')
    {
        if ($index == '')
        {
            if ( ! isset($this->config[$item]))
            {
                return FALSE;
            }

            $pref = $this->config[$item];
        }
        else
        {
            if ( ! isset($this->config[$item]))
            {
                return FALSE;
            }

            if ( ! isset($this->config[$item][$index]))
            {
                return FALSE;
            }

            $pref = $this->config[$item][$index];
        }

        return $pref;
    }



Bug in System->Libraries->Config.php - El Forum - 07-16-2008

[eluser]xwero[/eluser]
you should switch the parameters for the item method and then it should be fine.

Changing parameters because of grammar causes confusion.


Bug in System->Libraries->Config.php - El Forum - 07-17-2008

[eluser]ErwinVanHoof[/eluser]
Could you please explain.