Created
August 7, 2019 18:56
-
-
Save parzibyte/01546356defdf724b30b0f35de294471 to your computer and use it in GitHub Desktop.
Ejemplo de modelo en CodeIgniter 3 - https://parzibyte.me/blog/2018/10/11/ejemplo-anatomia-modelo-codeigniter-3/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ProductoModel extends CI_Model{ | |
public $id; | |
public $codigo; | |
public $descripcion; | |
public $precioVenta; | |
public $precioCompra; | |
public $existencia; | |
public function __construct(){ | |
$this->load->database(); | |
} | |
public function nuevo($codigo, $descripcion, $precioVenta, $precioCompra, $existencia){ | |
$this->codigo = $codigo; | |
$this->descripcion = $descripcion; | |
$this->precioVenta = $precioVenta; | |
$this->precioCompra = $precioCompra; | |
$this->existencia = $existencia; | |
return $this->db->insert('productos', $this); | |
} | |
public function guardarCambios($id, $codigo, $descripcion, $precioVenta, $precioCompra, $existencia){ | |
$this->id = $id; | |
$this->codigo = $codigo; | |
$this->descripcion = $descripcion; | |
$this->precioVenta = $precioVenta; | |
$this->precioCompra = $precioCompra; | |
$this->existencia = $existencia; | |
return $this->db->update('productos', $this, array("id" => $id)); | |
} | |
public function todos(){ | |
return $this->db->get("productos")->result(); | |
} | |
public function eliminar($id){ | |
return $this->db->delete("productos", array("id" => $id)); | |
} | |
public function uno($id){ | |
return $this->db->get_where("productos", array("id" => $id))->row(); | |
} | |
public function porCodigoDeBarras($codigoDeBarras){ | |
return $this->db->get_where("productos", array("codigo" => $codigoDeBarras))->row(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment