Public Member Functions | |
| CI_Pagination ($params=array()) | |
| Constructor. | |
| initialize ($params=array()) | |
| Initialize Preferences. | |
| create_links () | |
| Generate the pagination links. | |
Public Attributes | |
| $base_url = '' | |
| $total_rows = '' | |
| $per_page = 10 | |
| $num_links = 2 | |
| $cur_page = 0 | |
| $first_link = '‹ First' | |
| $next_link = '>' | |
| $prev_link = '<' | |
| $last_link = 'Last ›' | |
| $uri_segment = 3 | |
| $full_tag_open = '' | |
| $full_tag_close = '' | |
| $first_tag_open = '' | |
| $first_tag_close = ' ' | |
| $last_tag_open = ' ' | |
| $last_tag_close = '' | |
| $cur_tag_open = ' <b>' | |
| $cur_tag_close = '</b>' | |
| $next_tag_open = ' ' | |
| $next_tag_close = ' ' | |
| $prev_tag_open = ' ' | |
| $prev_tag_close = '' | |
| $num_tag_open = ' ' | |
| $num_tag_close = '' | |
| $page_query_string = FALSE | |
| $query_string_segment = 'per_page' | |
Definition at line 27 of file Pagination.php.
| CI_Pagination::CI_Pagination | ( | $ | params = array() |
) |
Constructor.
public
| array | initialization parameters |
Definition at line 62 of file Pagination.php.
References initialize(), and log_message().
00063 { 00064 if (count($params) > 0) 00065 { 00066 $this->initialize($params); 00067 } 00068 00069 log_message('debug', "Pagination Class Initialized"); 00070 }

| CI_Pagination::create_links | ( | ) |
Generate the pagination links.
public
Definition at line 103 of file Pagination.php.
References $CI, get_instance(), and show_error().
00104 { 00105 // If our item count or per-page total is zero there is no need to continue. 00106 if ($this->total_rows == 0 OR $this->per_page == 0) 00107 { 00108 return ''; 00109 } 00110 00111 // Calculate the total number of pages 00112 $num_pages = ceil($this->total_rows / $this->per_page); 00113 00114 // Is there only one page? Hm... nothing more to do here then. 00115 if ($num_pages == 1) 00116 { 00117 return ''; 00118 } 00119 00120 // Determine the current page number. 00121 $CI =& get_instance(); 00122 00123 if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) 00124 { 00125 if ($CI->input->get($this->query_string_segment) != 0) 00126 { 00127 $this->cur_page = $CI->input->get($this->query_string_segment); 00128 00129 // Prep the current page - no funny business! 00130 $this->cur_page = (int) $this->cur_page; 00131 } 00132 } 00133 else 00134 { 00135 if ($CI->uri->segment($this->uri_segment) != 0) 00136 { 00137 $this->cur_page = $CI->uri->segment($this->uri_segment); 00138 00139 // Prep the current page - no funny business! 00140 $this->cur_page = (int) $this->cur_page; 00141 } 00142 } 00143 00144 $this->num_links = (int)$this->num_links; 00145 00146 if ($this->num_links < 1) 00147 { 00148 show_error('Your number of links must be a positive number.'); 00149 } 00150 00151 if ( ! is_numeric($this->cur_page)) 00152 { 00153 $this->cur_page = 0; 00154 } 00155 00156 // Is the page number beyond the result range? 00157 // If so we show the last page 00158 if ($this->cur_page > $this->total_rows) 00159 { 00160 $this->cur_page = ($num_pages - 1) * $this->per_page; 00161 } 00162 00163 $uri_page_number = $this->cur_page; 00164 $this->cur_page = floor(($this->cur_page/$this->per_page) + 1); 00165 00166 // Calculate the start and end numbers. These determine 00167 // which number to start and end the digit links with 00168 $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1; 00169 $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; 00170 00171 // Is pagination being used over GET or POST? If get, add a per_page query 00172 // string. If post, add a trailing slash to the base URL if needed 00173 if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) 00174 { 00175 $this->base_url = rtrim($this->base_url).AMP.$this->query_string_segment.'='; 00176 } 00177 else 00178 { 00179 $this->base_url = rtrim($this->base_url, '/') .'/'; 00180 } 00181 00182 // And here we go... 00183 $output = ''; 00184 00185 // Render the "First" link 00186 if ($this->cur_page > $this->num_links) 00187 { 00188 $output .= $this->first_tag_open.'<a href="'.$this->base_url.'">'.$this->first_link.'</a>'.$this->first_tag_close; 00189 } 00190 00191 // Render the "previous" link 00192 if ($this->cur_page != 1) 00193 { 00194 $i = $uri_page_number - $this->per_page; 00195 if ($i == 0) $i = ''; 00196 $output .= $this->prev_tag_open.'<a href="'.$this->base_url.$i.'">'.$this->prev_link.'</a>'.$this->prev_tag_close; 00197 } 00198 00199 // Write the digit links 00200 for ($loop = $start -1; $loop <= $end; $loop++) 00201 { 00202 $i = ($loop * $this->per_page) - $this->per_page; 00203 00204 if ($i >= 0) 00205 { 00206 if ($this->cur_page == $loop) 00207 { 00208 $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page 00209 } 00210 else 00211 { 00212 $n = ($i == 0) ? '' : $i; 00213 $output .= $this->num_tag_open.'<a href="'.$this->base_url.$n.'">'.$loop.'</a>'.$this->num_tag_close; 00214 } 00215 } 00216 } 00217 00218 // Render the "next" link 00219 if ($this->cur_page < $num_pages) 00220 { 00221 $output .= $this->next_tag_open.'<a href="'.$this->base_url.($this->cur_page * $this->per_page).'">'.$this->next_link.'</a>'.$this->next_tag_close; 00222 } 00223 00224 // Render the "Last" link 00225 if (($this->cur_page + $this->num_links) < $num_pages) 00226 { 00227 $i = (($num_pages * $this->per_page) - $this->per_page); 00228 $output .= $this->last_tag_open.'<a href="'.$this->base_url.$i.'">'.$this->last_link.'</a>'.$this->last_tag_close; 00229 } 00230 00231 // Kill double slashes. Note: Sometimes we can end up with a double slash 00232 // in the penultimate link so we'll kill all double slashes. 00233 $output = preg_replace("#([^:])//+#", "\\1/", $output); 00234 00235 // Add the wrapper HTML if exists 00236 $output = $this->full_tag_open.$output.$this->full_tag_close; 00237 00238 return $output; 00239 }

| CI_Pagination::initialize | ( | $ | params = array() |
) |
Initialize Preferences.
public
| array | initialization parameters |
Definition at line 81 of file Pagination.php.
Referenced by CI_Pagination().
00082 { 00083 if (count($params) > 0) 00084 { 00085 foreach ($params as $key => $val) 00086 { 00087 if (isset($this->$key)) 00088 { 00089 $this->$key = $val; 00090 } 00091 } 00092 } 00093 }

| CI_Pagination::$base_url = '' |
Definition at line 29 of file Pagination.php.
| CI_Pagination::$cur_page = 0 |
Definition at line 33 of file Pagination.php.
| CI_Pagination::$cur_tag_close = '</b>' |
Definition at line 46 of file Pagination.php.
| CI_Pagination::$cur_tag_open = ' <b>' |
Definition at line 45 of file Pagination.php.
| CI_Pagination::$first_link = '‹ First' |
Definition at line 34 of file Pagination.php.
| CI_Pagination::$first_tag_close = ' ' |
Definition at line 42 of file Pagination.php.
| CI_Pagination::$first_tag_open = '' |
Definition at line 41 of file Pagination.php.
| CI_Pagination::$full_tag_close = '' |
Definition at line 40 of file Pagination.php.
| CI_Pagination::$full_tag_open = '' |
Definition at line 39 of file Pagination.php.
| CI_Pagination::$last_link = 'Last ›' |
Definition at line 37 of file Pagination.php.
| CI_Pagination::$last_tag_close = '' |
Definition at line 44 of file Pagination.php.
| CI_Pagination::$last_tag_open = ' ' |
Definition at line 43 of file Pagination.php.
| CI_Pagination::$next_link = '>' |
Definition at line 35 of file Pagination.php.
| CI_Pagination::$next_tag_close = ' ' |
Definition at line 48 of file Pagination.php.
| CI_Pagination::$next_tag_open = ' ' |
Definition at line 47 of file Pagination.php.
| CI_Pagination::$num_links = 2 |
Definition at line 32 of file Pagination.php.
| CI_Pagination::$num_tag_close = '' |
Definition at line 52 of file Pagination.php.
| CI_Pagination::$num_tag_open = ' ' |
Definition at line 51 of file Pagination.php.
| CI_Pagination::$page_query_string = FALSE |
Definition at line 53 of file Pagination.php.
| CI_Pagination::$per_page = 10 |
Definition at line 31 of file Pagination.php.
| CI_Pagination::$prev_link = '<' |
Definition at line 36 of file Pagination.php.
| CI_Pagination::$prev_tag_close = '' |
Definition at line 50 of file Pagination.php.
| CI_Pagination::$prev_tag_open = ' ' |
Definition at line 49 of file Pagination.php.
| CI_Pagination::$query_string_segment = 'per_page' |
Definition at line 54 of file Pagination.php.
| CI_Pagination::$total_rows = '' |
Definition at line 30 of file Pagination.php.
| CI_Pagination::$uri_segment = 3 |
Definition at line 38 of file Pagination.php.