![]() |
Override database method - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Override database method (/showthread.php?tid=62889) |
Override database method - HugoDias - 09-04-2015 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) { Hook to change the Database - It's post_controller_constructor Code: class ChangeDatabase{ RE: Override database method - mwhitney - 09-08-2015 The only time you're calling your method with the extra parameters, you're passing true as the second parameter, which means you are returning the result of calling DB($params, null), but you aren't saving the result, so $CI->db doesn't change and you don't have a reference to the DB class you just loaded. Further, when you pass true as the second parameter, there's no real difference between your database() method and the CI2 loader's database() method, because the check under the comment "Do we even need to load the database class?" will skip the "return FALSE;" line once it sees that $return is true. It would be cleaner to do something like this: PHP Code: class MY_Loader extends CI_Loader |