<?php
namespace application\models;

class MyModel_B extends \CI_Model
{
    protected $db_server;
    protected $table;
    protected $idTabla;
    
    public function __construct()
    {
        parent::__construct();
    }
    public function guardar($objeto,$id)
    {
        /*if((int)$objeto->__get($id)==0){
            $this->driver->insert($this->table,$objeto);
            $objeto->__set($id,$this->db_server->insert_id());
        }else{
            $this->sentenciaUpdate($objeto, $id);
        }*/
    }
    public function guardarArray(&$array,$idTabla)
    {
        if((int)$array[$idTabla]==0){
            $this->db_server->insert($this->table,$array);
            $array[$idTabla]=$this->db_server->insert_id();
        }else{
            $this->sentenciaUpdate($array, $idTabla);
        }
    }
    protected function sentenciaUpdate($array,$idTabla)
    {
        $this->db_server->where($idTabla,$array[$idTabla]);
        $this->db_server->update($this->table,$array);
    }
    protected function getArrayById($idTabla,$valor){
        $this->db_server->select("*");
        $this->db_server->from($this->table);
        $this->db_server->where($idTabla,$valor);
        $res=$this->db_server->get();
        return $res->row_array();
    }
}

