application/core/My_Model.php
/**
     * Save data 
     * @return int Last insert id if insert operation is done
     */
Save data
@return int Last insert id if insert operation is done
Save data @return int Last insert id if insert operation is done
public function save()
    {
        $data = [];
        $primary = $this->primary;
        foreach ($this->columns as $name => $meta)
        {
            $data[$name] = $this->{$name} ;
        }
        if($this->{$primary})
        {
            $where = [
                $primary => $this->{$primary}
            ];
            $this->db->update(  $this->getTable(), $data,$where );
        }
        else
        {
            $this->db->insert(  $this->getTable(), $data);
            return $this->db->insert_id();
        }
    }
public function save ( ) { $ data = [ ] ; $ primary = $ this -> primary ; foreach ( $ this -> columns as $ name => $ meta ) { $ data [ $ name ] = $ this -> { $ name } ; } if ( $ this -> { $ primary } ) { $ where = [ $ primary => $ this -> { $ primary } ] ; $ this -> db -> update ( $ this -> getTable ( ) , $ data , $ where ) ; } else { $ this -> db -> insert ( $ this -> getTable ( ) , $ data ) ; return $ this -> db -> insert_id ( ) ; } }
Save data
 @return int Last insert id if insert operation is done
Save data @return int Last insert id if insert operation is done