Adding database functionallity - 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: Adding database functionallity (/showthread.php?tid=61652) |
Adding database functionallity - JustMoes - 05-04-2015 Hello, I want to add THIS functionallity to the db->insert function, but i have no idea how to add such functionallity. I thought i could do something like this: Code: class MY_db extends CI_db { Can anyone tell me where i should put this code and how i can (auto)load the class? Greetz PS: Sorry for my awfull English RE: Adding database functionallity - mwhitney - 05-04-2015 You should probably do this in a base model (MY_Model.php) instead of trying to extend the database library. RE: Adding database functionallity - Urastor - 05-06-2015 As mwhitney said, extending the db of CI isn't the way to go here. You could add a model (MY_Model) to your core folder and extends CI_Model. To get access to every model, run parent::__construct(); in the constructor of MY_Model. Then simply overwrite insert in MY_Model, like this: PHP Code: <?php This is also a nice way to get ride of typing the table everytime, because you could add a protected field $table to the class and the method use it via $this->table. In another model, which extends MY_Model., you then can overwrite $table, so that for example a user model, which uses a user table, automatically uses $table instead of typing the user table every time. PHP Code: <?php But this is optional. RE: Adding database functionallity - JustMoes - 05-10-2015 Thanks for your help and explanation. I've found a tutorial by Joost van Veen about the MY_Model thing, very clear tutorial in my opinion. |