[eluser]m4ikel[/eluser]
Solution to get the database driver running in the Router.php
NOTICE: This is a change on CI Core level, and this change will be overwriten by a system update. So please be aware of this! Also change this at your own risk.
CI VERSION: 1.7.2
FILE: system/codeigniter/CodeIgniter.php
Change Line: 91 -> 100
Code:
/*
* ------------------------------------------------------
* Instantiate the base classes
* ------------------------------------------------------
*/
$CFG =& load_class('Config');
$URI =& load_class('URI');
$RTR =& load_class('Router');
$OUT =& load_class('Output');
To:
Code:
/*
* ------------------------------------------------------
* Instantiate the base classes
* ------------------------------------------------------
*/
$CFG =& load_class('Config');
$URI =& load_class('URI');
//$RTR =& load_class('Router'); Added db support to Router.php -> see line: 150
$OUT =& load_class('Output');
Change Line: 147 -> 150
Code:
// Load the base controller class
load_class('Controller', FALSE);
// Load the local application controller
To
Code:
// Load the base controller class
load_class('Controller', FALSE);
// Load Router.php class
$RTR =& load_class('Router');
// Load the local application controller
Now inside the router.php load the database by doing the following:
Code:
$db =& load_class('Loader');
$db->database();
$ci =& get_instance();
Which you can simply use like normal
Code:
$ci->db->from('my_table');
$ci->db->where('my_id',2);
$ci->db->where('my_page',1);
$q = $ci->db->get();
ect. ect.
Now you are able to use the CI database inside the Router.php class. I havn't noticed any issues after changing this. But please report when they occur inside this topic.
Issues/Notice:
- get_instance() : Because of the hack get_instance() is loaded before all core elements have been loaded, you will be required to load them (if possible) manually inside the Router.php.