Created
August 21, 2013 10:51
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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