Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * CRUD Model - Ocrend Framework
- * Ejemplo de uso correcto para un CRUD usando rutas y la api rest
- */
- final class Crud extends Models implements OCREND {
- public function __construct() {
- parent::__construct();
- }
- final public function errores(array $data) {
- try {
- if(Func::emp($data['ejemplo'])) {
- throw new Exception('Error campo vacío.');
- }
- return false;
- } catch(Exception $e) {
- return array('success' => 0, 'message' => $e->getMessage());
- }
- }
- final public function crear(array $data) : array {
- $error = $this->errores($data);
- if(false !== $error) {
- return $error;
- }
- $i = array(
- 'ejemplo' => $data['ejemplo']
- );
- # ó también: $i['ejemplo'] = $data['ejemplo'];
- $this->db->insert('tabla',$i);
- return array('success' => 1, 'message' => 'Éxito');
- }
- final public function leer(bool $multi = true) {
- if($multi) {
- return $this->db->select('*','tabla');
- }
- return $this->db->select('*','tabla',"id='$this->id'");
- }
- final public function actualizar() : array {
- $error = $this->errores($data);
- if(false !== $error) {
- return $error;
- }
- $i = array(
- 'ejemplo' => $data['ejemplo']
- );
- # ó también: $i['ejemplo'] = $data['ejemplo'];
- $this->id = $this->db->scape($data['id']); # porque desde la api rest no se define $this->id ya que no existe la ruta.
- $this->db->update('tabla',$i,"id='$this->id'",'LIMIT 1');
- return array('success' => 1, 'message' => 'Éxito');
- }
- final public function borrar() {
- $this->db->delete('tabla',"id='$this->id'");
- Func::redir(URL . 'crud/');
- }
- public function __destruct() {
- parent::__destruct();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement