Skip to content

Instantly share code, notes, and snippets.

@linushstge
Created November 19, 2015 10:16
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 linushstge/db6fc9890a884388708f to your computer and use it in GitHub Desktop.
Save linushstge/db6fc9890a884388708f to your computer and use it in GitHub Desktop.
<?php
class Media_model extends CI_Model
{
private $table = 'media';
private $store = [];
function __construct()
{
parent::__construct();
if(!empty($this->store)) {
return;
}
$this->db->order_by('date', 'desc');
$media = $this->db->get($this->table)->result_array();
foreach($media as $file) {
$this->store[$file['id']] = $file;
}
}
public function all()
{
return $this->store;
}
public function limit($max = 25, $start = 1)
{
$this->db->limit($max, $start);
$this->db->order_by('date', 'desc');
return $this->db->get($this->table)->result_array();
}
public function byId($mediaId)
{
if(!$mediaId) {
return;
}
return $this->store[$mediaId];
}
public function count()
{
$q = $this->db->get($this->table);
return $q->num_rows();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment