From 2a6c1da49b38abb8767192a064b8c6b01d1e421e Mon Sep 17 00:00:00 2001 From: Robin Sowell Date: Mon, 24 May 2010 12:20:03 -0400 Subject: Added $prefix, $suffix and $first_url properties to Pagination library. --- system/libraries/Pagination.php | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index d6321f41c..ccd3e8261 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -27,6 +27,9 @@ class CI_Pagination { var $base_url = ''; // The page we are linking to + var $prefix = ''; // A custom prefix added to the path. + var $suffix = ''; // A custom suffix added to the path. + var $total_rows = ''; // Total number of items (database results) var $per_page = 10; // Max number of items you want shown per page var $num_links = 2; // Number of "digit" links to show before/after the currently viewed page @@ -42,6 +45,7 @@ class CI_Pagination { var $first_tag_close = ' '; var $last_tag_open = ' '; var $last_tag_close = ''; + var $first_url = ''; // Alternative URL for the First Page. var $cur_tag_open = ' '; var $cur_tag_close = ''; var $next_tag_open = ' '; @@ -185,15 +189,25 @@ class CI_Pagination { // Render the "First" link if ($this->cur_page > ($this->num_links + 1)) { - $output .= $this->first_tag_open.''.$this->first_link.''.$this->first_tag_close; + $first_url = ($this->first_url == '') ? $this->base_url : $this->first_url; + $output .= $this->first_tag_open.''.$this->first_link.''.$this->first_tag_close; } // Render the "previous" link if ($this->cur_page != 1) { $i = $uri_page_number - $this->per_page; - if ($i == 0) $i = ''; - $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; + + if ($i == 0 && $this->first_url != '') + { + $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; + } + else + { + $i = ($i == 0) ? '' : $this->prefix.$i.$this->suffix; + $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; + } + } // Write the digit links @@ -210,7 +224,17 @@ class CI_Pagination { else { $n = ($i == 0) ? '' : $i; - $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; + + if ($n == '' && $this->first_url != '') + { + $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; + } + else + { + $n = ($n == '') ? '' : $this->prefix.$n.$this->suffix; + + $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; + } } } } @@ -218,14 +242,14 @@ class CI_Pagination { // Render the "next" link if ($this->cur_page < $num_pages) { - $output .= $this->next_tag_open.''.$this->next_link.''.$this->next_tag_close; + $output .= $this->next_tag_open.''.$this->next_link.''.$this->next_tag_close; } // Render the "Last" link if (($this->cur_page + $this->num_links) < $num_pages) { $i = (($num_pages * $this->per_page) - $this->per_page); - $output .= $this->last_tag_open.''.$this->last_link.''.$this->last_tag_close; + $output .= $this->last_tag_open.''.$this->last_link.''.$this->last_tag_close; } // Kill double slashes. Note: Sometimes we can end up with a double slash -- cgit v1.2.3-24-g4f1b