CodeIgniter Forums
[ci 2.0] extend/overload db driver - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [ci 2.0] extend/overload db driver (/showthread.php?tid=38066)



[ci 2.0] extend/overload db driver - El Forum - 01-29-2011

[eluser]MVUG[/eluser]
Is it, with the new ci 2.0, possible to overload/extend a db driver, like the oci8 driver?


[ci 2.0] extend/overload db driver - El Forum - 01-29-2011

[eluser]BrianJM[/eluser]
Quote:Drivers are a special type of Library that has a parent class and any number of potential child classes. Child classes have access to the parent class, but not their siblings. Drivers provide an elegant syntax in your controllers for libraries that benefit from or require being broken down into discrete classes.

You can extend a library, so you should be able to extend a driver. Give it a try and report your results!

Creating Core System Classes
Creating Libraries


[ci 2.0] extend/overload db driver - El Forum - 02-14-2011

[eluser]MVUG[/eluser]
Does somebody have experience with this? I want to overload a DB driver, OCI8 driver.


[ci 2.0] extend/overload db driver - El Forum - 02-24-2011

[eluser]13ankster[/eluser]
You can view extend DB driver in FuelCMS Sourcecode
Code:
/** Load the database drivers **/
    public function database($params = '', $return = FALSE, $active_record = NULL) {
        if (class_exists('CI_DB', FALSE) AND $return == FALSE AND $active_record == NULL)
            return;

        require_once BASEPATH.'database/DB'.EXT;
        
        $db = DB($params, $active_record);
        
        // <!-- FUEL
        $my_driver = config_item('subclass_prefix').'DB_'.$db->dbdriver.'_driver';
        $my_driver_file = APPPATH.'core/'.$my_driver.EXT;
        
        if (file_exists($my_driver_file))
        {
            require_once($my_driver_file);
            $db = new $my_driver(get_object_vars($db));
        }

        if ($return === TRUE)
        {
            return $db;
        }
        //    return DB($params, $active_record);
        // FUEL -->
        CI::$APP->db = '';
        //CI::$APP->db = DB($params, $active_record);
        CI::$APP->db = $db;
        $this->_ci_assign_to_models();
        return CI::$APP->db;
    }