Last active
August 29, 2015 14:20
-
-
Save hedii/f9e76f891f86cb7b84d5 to your computer and use it in GitHub Desktop.
Codeigniter MY_Model
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 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