function barebones($offset = 1) { $base_paginator = new Iceo_paginator_base(); $base_result = $base_paginator->create_links($offset); $template_data['content'] = '<pre>' . print_r($base_result, true) . '</pre>'; $this->load->view('paginator/mainPage', $template_data); }
private function default_config() { /* * When setting up this configuration parameter for datasets, you can * calculate total_pages value as (int)((number_of_records - 1) / records_per_page) + 1 * * Here, number_of_records is, well, total number of records in dataset, * and records_per_page is, well, number of records you will list on one page, ok? */ $config['total_pages'] = 10; $config['window_size'] = 3; /* * Since extended class(es) override initialize() * method, we need to specifically call this class' initialize(). */ Iceo_paginator_base::initialize($config); }
public function create_links($offset = 0) { // Calculate current page based on $offset and number of rows per page $current_page = (int) ($offset / $this->rows_per_page) + 1; // Call base paginator link creation method. // We will process it's result afterwords to fit our // dataset navigation intentions. $pagination = parent::create_links($current_page); /* * Go through generated page numbers * and replace them with equivalent row offsets */ $page_links = array(); foreach ($pagination as $key => $pagination_item) { /* * We use is_array() here to distinguish * between 'page_links' and navigation links. */ if (is_array($pagination_item)) { // Only $pagination['page_links'] is array foreach ($pagination_item as $page_link) { // This converts page number to row offset. $link_offset = ($page_link['number'] - 1) * $this->rows_per_page; // We chose to show row offset here instead of page number. // Comment this out if you want page number instead //$page_link['number'] = $link_offset; // Only change link if it is not disabled if ($page_link['link'] != 'disabled') { $page_link['link'] = $this->build_link($link_offset); } $page_links[] = $page_link; } } else { // Elements that are not array are 'first', 'prev', 'next' and 'last' if ($pagination_item != 'disabled') { // Page number to row offset. $pagination_item = ($pagination_item - 1) * $this->rows_per_page; $pagination_item = $this->build_link($pagination_item); $pagination[$key] = $pagination_item; } } } $pagination['page_links'] = $page_links; return $pagination; }