Hi everybody \o
I'm working in a feature that requests the change of database at execution time. I already read and search a lot,without progress. Actually I'm making a override from a core method(database - in core/Loader.php) with a MY_Loader class and call it from a hook.
What happens next is the problem. The params are not accepted,it's like I had not pass it to the function call. I have added a fourth param,to force the reload. Any help would be appreciated.
MY_Loader.php
Code:
function database($params = '', $return = FALSE, $active_record = NULL,$force_load = FALSE) {
// Grab the super object
$CI =& get_instance();
// Do we even need to load the database class?
if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db) AND $force_load == FALSE)
{
return FALSE;
}
require_once(BASEPATH.'database/DB.php');
if ($return === TRUE)
{
return DB($params, $active_record);
}
// Initialize the db variable. Needed to prevent
// reference errors with some configurations
$CI->db = '';
// Load the DB class
$CI->db =& DB($params, $active_record);
}
Hook to change the Database -
It's post_controller_constructor
Code:
class ChangeDatabase{
function changeToRead(){
$CI =& get_instance();
if($CI->session->userdata['usercode'] !== $CI->session->userdata['usercodeloged']){
$CI->load->database("canOnlyRead",true,null,true);
}else{
$CI->load->database('default');
}
}
}