extending the database class in a proper way - 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: extending the database class in a proper way (/showthread.php?tid=58676) |
extending the database class in a proper way - El Forum - 07-05-2013 [eluser]xeroblast[/eluser] just wanted to share it. because all i see are hacking the codeigniter core. and the problem on hacking its core is when you try to update your codeigniter and your application went nuts.. let start by knowing/setting your subclass_prefix in "application/config/config.php" e.g ("MY_"). so every filename of your subclass start with that prefix we create your subclass loader in "application/core" directory and name it "MY_Loader.php" and copy the function ( "function database()" ) of the original Loader.php in "system/core/Loader.php" to your "MY_Loader.php" find and change the code according below -- dont forget to extend your class "extends CI_Loader" Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); we create a folder named "database" then we copy the file "system/database/DB.php" to our newly created directory "application/database" and then we renamed it "MY_DB.php". open "MY_DB.php", find and replace/comment out the code according below Code: /** comment out this original code now you're almost done... so when extending the active record class. create the file "MY_DB_active_record.php" in "application/database" directory. ( "application/database/MY_DB_active_record.php" ) -- dont forget to extend your class "extends CI_DB_active_record" Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); and when extending the driver class, create a directory in "application/database" named "drivers". and inside "drivers" directory create another directory with database driver name (e.g. "mysql", "mssql", "postgre"). and inside the database driver name directory, create the driver file "MY_DB_mysql_driver.php". ( "application/database/drivers/mysql/MY_DB_mysql_driver.php" - for mysql ) -- dont forget to extend your class "extends CI_DB_mysql_driver" Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |