Beispiel #1
0
 public function paginate($page = 1, $where = array(), $limit = 10)
 {
     // get filtered results
     $where = array_merge($where, $this->where);
     $offset = $page <= 1 ? 0 : ($page - 1) * $limit;
     $this->db->limit($limit, $offset);
     $results = parent::get_many_by($where);
     // get counts (e.g. for pagination)
     $count_results = count($results);
     $count_total = parent::count_by($where);
     $total_pages = ceil($count_total / $limit);
     $counts = array('from_num' => $count_results == 0 ? 0 : $offset + 1, 'to_num' => $count_results == 0 ? 0 : $offset + $count_results, 'total_num' => $count_total, 'curr_page' => $page, 'total_pages' => $count_results == 0 ? 1 : $total_pages, 'limit' => $limit);
     return array('data' => $results, 'counts' => $counts);
 }
Beispiel #2
0
 public function paginate($page = 1, $where = array(), $limit = NULL)
 {
     // decide per-page limit by: 1) $this->limit; 2) a default value (10)
     if (!empty($this->limit) && $limit === NULL) {
         $limit = $this->limit;
     } else {
         if ($limit === NULL) {
             $limit = 10;
         }
     }
     // avoid overrided by $this->limit
     $this->limit = NULL;
     // get filtered results
     $where = array_merge($where, $this->where);
     $offset = $page <= 1 ? 0 : ($page - 1) * $limit;
     $this->db->limit($limit, $offset);
     $results = parent::get_many_by($where);
     // get counts (e.g. for pagination)
     $count_results = count($results);
     $count_total = parent::count_by($where);
     $total_pages = ceil($count_total / $limit);
     $counts = array('from_num' => $count_results == 0 ? 0 : $offset + 1, 'to_num' => $count_results == 0 ? 0 : $offset + $count_results, 'total_num' => $count_total, 'curr_page' => $page, 'total_pages' => $count_results == 0 ? 1 : $total_pages, 'limit' => $limit);
     return array('data' => $results, 'counts' => $counts);
 }