From 33987e6a318eaf853f626f950573601928547f8f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 24 Dec 2011 19:48:45 +0200 Subject: Improve the Pagination library --- system/libraries/Pagination.php | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index eea953ae4..008c15192 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -1,4 +1,4 @@ -total_rows / $this->per_page); // Is there only one page? Hm... nothing more to do here then. - if ($num_pages == 1) + if ($num_pages === 1) { return ''; } @@ -146,25 +146,16 @@ class CI_Pagination { { if ($CI->input->get($this->query_string_segment) != $base_page) { - $this->cur_page = $CI->input->get($this->query_string_segment); - - // Prep the current page - no funny business! - $this->cur_page = (int) $this->cur_page; + $this->cur_page = (int) $CI->input->get($this->query_string_segment); } } - else + elseif ($CI->uri->segment($this->uri_segment) != $base_page) { - if ($CI->uri->segment($this->uri_segment) != $base_page) - { - $this->cur_page = $CI->uri->segment($this->uri_segment); - - // Prep the current page - no funny business! - $this->cur_page = (int) $this->cur_page; - } + $this->cur_page = (int) $CI->uri->segment($this->uri_segment); } - // Set current page to 1 if using page numbers instead of offset - if ($this->use_page_numbers AND $this->cur_page == 0) + // Set current page to 1 if it's not valid or if using page numbers instead of offset + if ( ! is_numeric($this->cur_page) OR ($this->use_page_numbers AND $this->cur_page == 0)) { $this->cur_page = $base_page; } @@ -176,11 +167,6 @@ class CI_Pagination { show_error('Your number of links must be a positive number.'); } - if ( ! is_numeric($this->cur_page)) - { - $this->cur_page = $base_page; - } - // Is the page number beyond the result range? // If so we show the last page if ($this->use_page_numbers) @@ -310,4 +296,4 @@ class CI_Pagination { // END Pagination Class /* End of file Pagination.php */ -/* Location: ./system/libraries/Pagination.php */ \ No newline at end of file +/* Location: ./system/libraries/Pagination.php */ -- cgit v1.2.3-24-g4f1b