From 74d0e23eae054c49bbf7d9d5c4738fa5a63754cf Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 5 Feb 2015 13:36:00 +0200 Subject: Allow a database to be loaded before controller instantiation --- system/database/DB.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index d411b679e..8ea7ca6fa 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -61,18 +61,23 @@ function &DB($params = '', $query_builder_override = NULL) } include($file_path); - // Make packages contain database config files - foreach (get_instance()->load->get_package_paths() as $path) + + // Make packages contain database config files, + // given that the controller instance already exists + if (class_exists('CI_Controller', FALSE)) { - if ($path !== APPPATH) + foreach (get_instance()->load->get_package_paths() as $path) { - if (file_exists($file_path = $path.'config/'.ENVIRONMENT.'/database.php')) - { - include($file_path); - } - elseif (file_exists($file_path = $path.'config/database.php')) + if ($path !== APPPATH) { - include($file_path); + if (file_exists($file_path = $path.'config/'.ENVIRONMENT.'/database.php')) + { + include($file_path); + } + elseif (file_exists($file_path = $path.'config/database.php')) + { + include($file_path); + } } } } -- cgit v1.2.3-24-g4f1b