CI_Config::load PHP Method

load() public method

Load Config File
public load ( string $file = '', boolean $use_sections = FALSE, boolean $fail_gracefully = FALSE ) : boolean
$file string Configuration file name
$use_sections boolean Whether configuration values should be loaded into their own section
$fail_gracefully boolean Whether to just return FALSE or display an error message
return boolean TRUE if the file was loaded correctly or FALSE on failure
    public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
    {
        $file = $file === '' ? 'config' : str_replace('.php', '', $file);
        $loaded = FALSE;
        foreach ($this->_config_paths as $path) {
            foreach (array($file, ENVIRONMENT . DIRECTORY_SEPARATOR . $file) as $location) {
                $file_path = $path . 'config/' . $location . '.php';
                if (in_array($file_path, $this->is_loaded, TRUE)) {
                    return TRUE;
                }
                if (!file_exists($file_path)) {
                    continue;
                }
                include $file_path;
                if (!isset($config) or !is_array($config)) {
                    if ($fail_gracefully === TRUE) {
                        return FALSE;
                    }
                    show_error('Your ' . $file_path . ' file does not appear to contain a valid configuration array.');
                }
                if ($use_sections === TRUE) {
                    $this->config[$file] = isset($this->config[$file]) ? array_merge($this->config[$file], $config) : $config;
                } else {
                    $this->config = array_merge($this->config, $config);
                }
                $this->is_loaded[] = $file_path;
                $config = NULL;
                $loaded = TRUE;
                log_message('debug', 'Config file loaded: ' . $file_path);
            }
        }
        if ($loaded === TRUE) {
            return TRUE;
        } elseif ($fail_gracefully === TRUE) {
            return FALSE;
        }
        show_error('The configuration file ' . $file . '.php does not exist.');
    }

Usage Example

コード例 #1
0
 public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
 {
     // first we need to check if this is called before CI_controller
     // if yes, well just use default
     if (!class_exists('CI_controller')) {
         return parent::load($file, $use_sections, $fail_gracefully);
     }
     if (in_array($file, $this->is_loaded, TRUE)) {
         return $this->item($file);
     }
     $_module = Modules::$current;
     if ($path = modules::find($file, $_module, 'config')) {
         // this file expected contain $config var
         include $path;
         if (!isset($config) or !is_array($config)) {
             show_error("{$path} does not contain a valid config array");
         }
         log_message('debug', "File loaded: {$path}");
         $current_config =& $this->config;
         if ($use_sections === TRUE) {
             if (isset($current_config[$file])) {
                 $current_config[$file] = array_merge($current_config[$file], $config);
             } else {
                 $current_config[$file] = $config;
             }
         } else {
             $current_config = array_merge($current_config, $config);
         }
         $this->is_loaded[] = $file;
         unset($config);
         return $this->item($file);
     }
     return parent::load($file, $use_sections, $fail_gracefully);
 }
All Usage Examples Of CI_Config::load