Welcome Guest, Not a member yet? Register   Sign In
Config Class Behavior
#1

[eluser]stevea[/eluser]
I'm looking at a controller that has:

1.
Code:
$this->config->load('uploader_settings', TRUE);

in the constructor. So we're adding the members of uploader_settings.php to the main config as a new array member.

Then in a function of the class we have:

2.
Code:
$conf['img_path'] = $this->config->item('img_path', 'uploader_settings');



It turns out that the 'img_path' item is not in 'uploader_settings.php but it is in the main config.php. From reading about the config class in the User Guide I wouldn't expect line 2 to fail back to the main config file when the 'img_path' item was not found in uploader_settings, which , it appears, must happen for this code to work.

Will it fail back to config?

Thanks.,
Steve
#2

[eluser]Aken[/eluser]
What version of CI are you using? Looking at 2.1.3, it should not fall back - if the $index param (second param) is included, it looks for the existence of that index, and then the config item under that index. If one or the other does not exist, then FALSE is returned.

You can always look at the Config library's code yourself, too. It'll give you a definitive answer as to how it works.
#3

[eluser]stevea[/eluser]
I'm running 2.0.2, and the config-> item code in core seems pretty clear about returning FALSE for this case:
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;
}

So maybe it is returning FALSE here and it gets the parameters later.

Anyway, thanks for your suggestions.

Steve




Theme © iAndrew 2016 - Forum software by © MyBB