Skip to content

Instantly share code, notes, and snippets.

@patpohler
Created August 3, 2014 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save patpohler/1a93b2c9a5495e83b200 to your computer and use it in GitHub Desktop.
Save patpohler/1a93b2c9a5495e83b200 to your computer and use it in GitHub Desktop.
Model class inheriting from Base_model class. See Medium article for details:
<?php if(!defined('EXT')) exit("Invalid file request");
/**
* Post Model Class
*
* @package ci_model_example
* @author Patrick Pohler ppohler@anecka.com
* @copyright Copyright (c) 2014, Patrick Pohler
* @link http://www.anecka.com/rets_press
* @license MIT
*/
require PATH_THIRD."ci_model_example/models/base_model.php";
class Post_child extends Base_model {
var $title = '';
var $name = '';
var $date = null;
var $author_secret = '';
function __construct() {
ee()->load->library('encrypt');
parent::__construct();
}
protected function _set_model_for_save($data) {
$this->site_id = $data['site_id'];
$this->title = $data['title'];
$this->name = $data['name'];
$this->date = $data['date'];
$this->author_secret = ee()->encrypt->encode($data['author_secret']);
}
protected function _set_model_for_return($row) {
$this->id = $row->id;
$this->site_id = $row->site_id;
$this->title = $row->title;
$this->name = $row->name;
$this->date = $row->date;
$this->author_secret = ee()->encrypt->decode($row->author_secret);
}
protected function _get_table(){
return "posts";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment