I was recently debugging an issue with Codeigniter Payments and HMVC. The issue was that config files were not being loaded if they were deeply nested – for example:
config/payments/my_gateway.php
The MX_Config path explodes the filepath provided on forward slashes, so if you do anything other than this->load->config(‘whatever’), the file you want won’t get loaded, since only the last segment will be sent to the CI_Config class.
I was able to implement a workaround by modifying the MX_Config class, and by passing TRUE as the third param when I loaded a config file in a spark (this asks the config loader to fail gracefully, returning FALSE when a config file isn’t found instead of using the show_error helper).
Alternatively, you can pass the
To MX_Config, replace the load function with:
public function load($file = ‘config’, $use_sections = FALSE, $fail_gracefully = FALSE, $_module = ”) {
$original_file = $file;
if (in_array($file, $this->is_loaded, TRUE)) return $this->item($file);
$_module OR $_module = CI::$APP->router->fetch_module();
list($path, $file) = Modules::find($file, $_module, ‘config/’);
if ($path === FALSE) {
$try1 = parent::load($file, $use_sections, $fail_gracefully);
if($try1) return $this->item($file);
$try2 = parent::load($original_file, $use_sections, $fail_gracefully);
if($try2) return $this->item($original_file);
}
if ($config = Modules::load_file($file, $path, ‘config’)) {
/* reference to the config array */
$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);
}
}
This tries the original path if the config file isn’t found at the reformatted path. Kind of a hack, I know – but I couldn’t find a more elegant way around this. Any suggestions are appreciated – but if you just need it to work – I hope this helps.
