Welcome Guest, Not a member yet? Register   Sign In
Adding database functionallity
#3

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

class MY_Model extends CI_Model {
 
 public function 
__construct()
 {
 
parent::__construct();
 }

 public function 
insert($table ''$set NULL$escape NULL$update_on_duplicate FALSE)
 {
 if(!
update_on_duplicate)
 return 
parent::insert($table$set$escape);

 
//your code
 
}


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

class MY_Model extends CI_Model {
 
 protected 
$table '';

 public function 
__construct()
 {
 
    parent::__construct();
 }

 public function 
insert($set NULL$escape NULL$update_on_duplicate FALSE)
 {
 
    if(!update_on_duplicate)
 
        return parent::insert($this->table$set$escape);

 
    //your code
 
}


But this is optional. Tongue
-.-.-.-.-.-.-.-.- Angel -.-.-.-.-.-.-.-.-
Reply


Messages In This Thread
Adding database functionallity - by JustMoes - 05-04-2015, 08:00 AM
RE: Adding database functionallity - by mwhitney - 05-04-2015, 02:00 PM
RE: Adding database functionallity - by Urastor - 05-06-2015, 12:49 PM
RE: Adding database functionallity - by JustMoes - 05-10-2015, 11:26 PM



Theme © iAndrew 2016 - Forum software by © MyBB