Skip to content

Instantly share code, notes, and snippets.

@hedii
Last active August 29, 2015 14:20
Show Gist options
  • Save hedii/f9e76f891f86cb7b84d5 to your computer and use it in GitHub Desktop.
Save hedii/f9e76f891f86cb7b84d5 to your computer and use it in GitHub Desktop.

Revisions

  1. hedii renamed this gist May 11, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. hedii created this gist May 11, 2015.
    83 changes: 83 additions & 0 deletions Codeigniter MY_Model
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,83 @@
    <?php defined('BASEPATH') OR exit('No direct script access allowed');

    /**
    * MY_Model class.
    *
    * @extends CI_model
    */
    class MY_Model extends CI_model {

    /**
    * create function.
    *
    * @access public
    * @param array $data (default: array())
    * @return bool
    */
    public function create($data = array()) {

    return $this->db->insert($this->table, $data);

    }

    /**
    * get function.
    *
    * @access public
    * @param array $where (default: array())
    * @return mixed
    */
    public function get($where = array()) {

    $this->db->from($this->table);
    $this->db->where($where);
    return $this->db->get()->result();

    }

    /**
    * update function.
    *
    * @access public
    * @param array $where (default: array())
    * @param array $data (default: array())
    * @return bool
    */
    public function update($where = array(), $data = array()) {

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

    }

    /**
    * delete function.
    *
    * @access public
    * @param array $where (default: array())
    * @return bool
    */
    public function delete($where = array()) {

    $this->db->from($this->table);
    $this->db->where($where);
    return (bool) $this->db->delete();

    }

    /**
    * count function.
    *
    * @access public
    * @param array $where (default: array())
    * @return int
    */
    public function count($where = array()) {

    $this->db->from($this->table);
    $this->db->where($where);
    return (int) $this->count_all_results();

    }

    }