Created
January 14, 2009 23:55
-
-
Save markwatson/47168 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* The global model! All hail potentate MY_Controller! | |
* It provides some great default queries... | |
*/ | |
class MY_Model extends Model | |
{ | |
var $default_table; | |
function get_all() | |
{ | |
// set up the query | |
$query = $this->db->get($this->default_table); | |
// run the query | |
$data = $query->result(); | |
// return data | |
return $data; | |
} | |
function get_one($id) | |
{ | |
// set up the query | |
$query = $this->db->get_where($this->default_table, array('id' => $id)); | |
// run the query | |
$data = $query->result(); | |
// return data | |
if (!empty($data)) return $data[0]; | |
else return FALSE; | |
} | |
function add($data) | |
{ | |
// simple: just save it, return if success | |
return $this->db->insert($this->default_table, $data); | |
} | |
function save($data, $id) | |
{ | |
$this->db->where('id', $id); | |
return $this->db->update($this->default_table, $data); | |
} | |
function delete($id) | |
{ | |
return $this->db->delete($this->default_table, array('id' => $id)); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment