Skip to content

Instantly share code, notes, and snippets.

@nazieb
Created August 21, 2013 10:51
Show Gist options
  • Select an option

  • Save nazieb/6292994 to your computer and use it in GitHub Desktop.

Select an option

Save nazieb/6292994 to your computer and use it in GitHub Desktop.
Custom loader library for CodeIgniter to autoload database groups other than $default_group
<?php
class MY_Loader extends CI_Loader {
public function database($params = '', $return = FALSE, $active_record = NULL)
{
parent::database($params, $return, $active_record);
if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php'))
{
if ( ! file_exists($file_path = APPPATH.'config/database.php'))
{
show_error('The configuration file database.php does not exist.');
}
}
include($file_path);
if ( ! isset($db) OR count($db) == 0) return;
$CI =& get_instance();
foreach($db as $group_name => $group)
{
if($group_name == $active_group) continue;
$property = 'db_'.$group_name;
if(property_exists($CI, $property)) continue;
$CI->$property = &parent::database($group_name);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment