summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/libraries/Pagination.php98
-rw-r--r--user_guide_src/source/changelog.rst1
-rw-r--r--user_guide_src/source/libraries/pagination.rst15
3 files changed, 74 insertions, 40 deletions
diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php
index 5a4ca8f10..75745dd48 100644
--- a/system/libraries/Pagination.php
+++ b/system/libraries/Pagination.php
@@ -36,39 +36,40 @@
*/
class CI_Pagination {
- public $base_url = ''; // The page we are linking to
- public $prefix = ''; // A custom prefix added to the path.
- public $suffix = ''; // A custom suffix added to the path.
- public $total_rows = 0; // Total number of items (database results)
- public $per_page = 10; // Max number of items you want shown per page
- public $num_links = 2; // Number of "digit" links to show before/after the currently viewed page
- public $cur_page = 0; // The current page being viewed
- public $use_page_numbers = FALSE; // Use page number for segment instead of offset
- public $first_link = '‹ First';
- public $next_link = '>';
- public $prev_link = '<';
- public $last_link = 'Last ›';
- public $uri_segment = 3;
- public $full_tag_open = '';
- public $full_tag_close = '';
- public $first_tag_open = '';
- public $first_tag_close = ' ';
- public $last_tag_open = ' ';
- public $last_tag_close = '';
- public $first_url = ''; // Alternative URL for the First Page.
- public $cur_tag_open = '&nbsp;<strong>';
- public $cur_tag_close = '</strong>';
- public $next_tag_open = '&nbsp;';
- public $next_tag_close = '&nbsp;';
- public $prev_tag_open = '&nbsp;';
- public $prev_tag_close = '';
- public $num_tag_open = '&nbsp;';
- public $num_tag_close = '';
- public $page_query_string = FALSE;
- public $query_string_segment = 'per_page';
- public $display_pages = TRUE;
- protected $_attributes = '';
- protected $_link_types = array();
+ protected $base_url = ''; // The page we are linking to
+ protected $prefix = ''; // A custom prefix added to the path.
+ protected $suffix = ''; // A custom suffix added to the path.
+ protected $total_rows = 0; // Total number of items (database results)
+ protected $per_page = 10; // Max number of items you want shown per page
+ protected $num_links = 2; // Number of "digit" links to show before/after the currently viewed page
+ protected $cur_page = 0; // The current page being viewed
+ protected $use_page_numbers = FALSE; // Use page number for segment instead of offset
+ protected $first_link = '&lsaquo; First';
+ protected $next_link = '&gt;';
+ protected $prev_link = '&lt;';
+ protected $last_link = 'Last &rsaquo;';
+ protected $uri_segment = 3;
+ protected $full_tag_open = '';
+ protected $full_tag_close = '';
+ protected $first_tag_open = '';
+ protected $first_tag_close = '&nbsp;';
+ protected $last_tag_open = '&nbsp;';
+ protected $last_tag_close = '';
+ protected $first_url = ''; // Alternative URL for the First Page.
+ protected $cur_tag_open = '&nbsp;<strong>';
+ protected $cur_tag_close = '</strong>';
+ protected $next_tag_open = '&nbsp;';
+ protected $next_tag_close = '&nbsp;';
+ protected $prev_tag_open = '&nbsp;';
+ protected $prev_tag_close = '';
+ protected $num_tag_open = '&nbsp;';
+ protected $num_tag_close = '';
+ protected $page_query_string = FALSE;
+ protected $query_string_segment = 'per_page';
+ protected $display_pages = TRUE;
+ protected $_attributes = '';
+ protected $_link_types = array();
+ protected $reuse_query_string = FALSE;
/**
* Constructor
@@ -222,6 +223,23 @@ class CI_Pagination {
// And here we go...
$output = '';
+ $query_string = '';
+
+ // Add anything in the query string back to the links
+ // Note: Nothing to do with query_string_segment or any other query string options
+ if ($this->reuse_query_string === TRUE)
+ {
+ $get = $CI->input->get();
+
+ // Unset the controll, method, old-school routing options
+ unset($get['c'], $get['m'], $get[$this->query_string_segment]);
+
+ // Put everything else onto the end
+ $query_string = (strpos($this->base_url, '&amp;') !== FALSE ? '&amp;' : '?') . http_build_query($get, '', '&amp;');
+
+ // Add this after the suffix to put it into more links easily
+ $this->suffix .= $query_string;
+ }
// Render the "First" link
if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1))
@@ -232,19 +250,19 @@ class CI_Pagination {
}
// Render the "previous" link
- if ($this->prev_link !== FALSE && $this->cur_page !== 1)
+ if ($this->prev_link !== FALSE && $this->cur_page !== 1)
{
$i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page;
if ($i === $base_page && $this->first_url !== '')
{
- $output .= $this->prev_tag_open.'<a href="'.$this->first_url.'"'.$this->_attributes.$this->_attr_rel('prev').'>'
+ $output .= $this->prev_tag_open.'<a href="'.$this->first_url.$query_string.'"'.$this->_attributes.$this->_attr_rel('prev').'>'
.$this->prev_link.'</a>'.$this->prev_tag_close;
}
else
{
- $i = ($i === $base_page) ? '' : $this->prefix.$i.$this->suffix;
- $output .= $this->prev_tag_open.'<a href="'.$this->base_url.$i.'"'.$this->_attributes.$this->_attr_rel('prev').'>'
+ $append = ($i === $base_page) ? $query_string : $this->prefix.$i.$this->suffix;
+ $output .= $this->prev_tag_open.'<a href="'.$this->base_url.$append.'"'.$this->_attributes.$this->_attr_rel('prev').'>'
.$this->prev_link.'</a>'.$this->prev_tag_close;
}
@@ -268,13 +286,13 @@ class CI_Pagination {
$n = ($i === $base_page) ? '' : $i;
if ($n === '' && ! empty($this->first_url))
{
- $output .= $this->num_tag_open.'<a href="'.$this->first_url.'"'.$this->_attributes.$this->_attr_rel('start').'>'
+ $output .= $this->num_tag_open.'<a href="'.$this->first_url.$query_string.'"'.$this->_attributes.$this->_attr_rel('start').'>'
.$loop.'</a>'.$this->num_tag_close;
}
else
{
- $n = ($n === '') ? '' : $this->prefix.$n.$this->suffix;
- $output .= $this->num_tag_open.'<a href="'.$this->base_url.$n.'"'.$this->_attributes.$this->_attr_rel('start').'>'
+ $append = ($n === '') ? $query_string : $this->prefix.$n.$this->suffix;
+ $output .= $this->num_tag_open.'<a href="'.$this->base_url.$append.'"'.$this->_attributes.$this->_attr_rel('start').'>'
.$loop.'</a>'.$this->num_tag_close;
}
}
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index f8eb59644..29084ed9b 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -170,6 +170,7 @@ Release Date: Not Released
- Added support for the anchor "rel" attribute.
- Added support for setting custom attributes.
- Deprecated usage of the "anchor_class" setting (use the new "attributes" setting instead).
+ - Added $config['reuse_query_string'] to allow automatic repopulation of query string arguments, combined with normal URI segments.
- Core
diff --git a/user_guide_src/source/libraries/pagination.rst b/user_guide_src/source/libraries/pagination.rst
index c4398d739..15b3675df 100644
--- a/user_guide_src/source/libraries/pagination.rst
+++ b/user_guide_src/source/libraries/pagination.rst
@@ -112,6 +112,21 @@ the pagination link will become.
Note that "per_page" is the default query string passed, however can be
configured using $config['query_string_segment'] = 'your_string'
+$config['reuse_query_string'] = FALSE;
+====================================
+
+By default your Query String arguments (nothing to do with other
+query string options) will be ignored. Setting this config to
+TRUE will add existing query string arguments back into the
+URL after the URI segment and before the suffix
+
+::
+
+ http://example.com/index.php/test/page/20?query=search%term
+
+This helps you mix together normal :doc:`URI Segments <../general/urls>`
+as well as query string arguments, which until 3.0 was not possible.
+
***********************
Adding Enclosing Markup
***********************