php - Code Igniter Active Records Update Records -


i new code igniter , follow through video tutorial create initial code however, having trouble updating records.

here code

class my_model extends ci_model {

const db_table = "abstract"; const db_table_pk = "abstract";  public function __construct() {     $this->load->database();  }   private function insert() {     $this->db->insert($this::db_table, $this);     $this->{$this::db_table_pk} = $this->db->insert_id(); }   private function update() {     $this->db->update($this::db_table, $this, $this::db_table_pk);         }  public function save() {     if(isset($this->{$this::db_table_pk}))     {         echo "inserting record";         $this->update();     }     else     {         echo "updating record";         $this->insert();     } } 

}

class publication extends my_model {

const db_table = "publication"; const db_table_pk = "publication_id";   public $publication_id; public $publication_name; 

}

class magazine extends ci_controller {

public function db_update_publication_record()

{     $this->load->model('publication');     $this->publication->publication_id = 2;     $this->publication->publication_name = "update record -- worked";     $this->publication->save();     echo "<tt><pre>".  var_export($this->publication, true)."</pre></tt>"; } 

}


when try update doesn't find db_table_pk , attempts insert, how can set primary key in model can update record.

please help

you have put array or string in 3rd paramater in :

$this->db->update($table, $update, $where);  

something :

$this->db->update($this::db_table, $this, array($this::db_table_pk => $this->{$this::db_table_pk})));   

but not sure "$this" in 2nd parameter works ?


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -