Skip to content

Instantly share code, notes, and snippets.

@hedii
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hedii/f9e76f891f86cb7b84d5 to your computer and use it in GitHub Desktop.
Save hedii/f9e76f891f86cb7b84d5 to your computer and use it in GitHub Desktop.
Codeigniter MY_Model
<?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();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment