Skip to content

Instantly share code, notes, and snippets.

@patpohler
Last active October 26, 2023 13:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save patpohler/225fe68324e6bdfb0e68 to your computer and use it in GitHub Desktop.
Save patpohler/225fe68324e6bdfb0e68 to your computer and use it in GitHub Desktop.
<?php if(!defined('EXT')) exit("Invalid file request");
/**
* Base Model Class
*
* @package ci_example
* @author Patrick Pohler ppohler@anecka.com
* @copyright Copyright (c) 2014, Patrick Pohler
* @link http://www.anecka.com/rets_press
* @license MIT
*/
abstract class Base_model extends CI_Model {
var $id;
var $site_id;
abstract protected function _set_model_for_save($data);
abstract protected function _set_model_for_return($row);
abstract protected function _get_table();
function __construct() {
parent::__construct();
}
public function get($id) {
$query = ee()->db->get_where($this->_get_table(), array('id' => $id));
if($query->num_rows() == 1) $this->_set_model_for_return($query->row());
}
public function get_by_site_id($site_id) {
$query = ee()->db->get_where($this->_get_table(), array('site_id' => $site_id));
if($query->num_rows() == 1) $this->_set_model_for_return($query->row());
}
public function insert($data) {
$this->_set_model_for_save($data);
ee()->db->insert($this->_get_table(), $this);
$this->id = ee()->db->insert_id();
}
public function update($data, $id) {
$this->_set_model_for_save($data);
$this->id = $id;
ee()->db->update($this->_get_table(), $this, array('id' => $id));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment