blob: 5f9d8a0f1861104e105c37927d4a8eaf08dae65b [file] [log] [blame]
adminb0dd10f2006-08-25 17:25:49 +00001<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Derek Allardafd99ac2008-01-19 19:59:14 +00002<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
adminb0dd10f2006-08-25 17:25:49 +00003<head>
4
Derek Jonesfd93d222008-05-06 15:18:50 +00005<title>Pagination Class : CodeIgniter User Guide</title>
adminb0dd10f2006-08-25 17:25:49 +00006
7<style type='text/css' media='all'>@import url('../userguide.css');</style>
8<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
9
admin17a890d2006-09-27 20:42:42 +000010<script type="text/javascript" src="../nav/nav.js"></script>
admin2296fc32006-09-27 21:07:02 +000011<script type="text/javascript" src="../nav/prototype.lite.js"></script>
admin17a890d2006-09-27 20:42:42 +000012<script type="text/javascript" src="../nav/moo.fx.js"></script>
Derek Allardb3412372007-10-25 12:15:16 +000013<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
adminb0dd10f2006-08-25 17:25:49 +000014
15<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
16<meta http-equiv='expires' content='-1' />
17<meta http-equiv= 'pragma' content='no-cache' />
18<meta name='robots' content='all' />
Derek Allard3d879d52008-01-18 19:41:32 +000019<meta name='author' content='ExpressionEngine Dev Team' />
Derek Allardd2df9bc2007-04-15 17:41:17 +000020<meta name='description' content='CodeIgniter User Guide' />
adminb0dd10f2006-08-25 17:25:49 +000021
22</head>
23<body>
24
25<!-- START NAVIGATION -->
26<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
27<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle.jpg" width="153" height="44" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
28<div id="masthead">
29<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
30<tr>
Derek Jones6b7b11f2008-05-06 16:07:27 +000031<td><h1>CodeIgniter User Guide Version 1.6.2</h1></td>
adminc0d5d522006-10-30 19:40:35 +000032<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
adminb0dd10f2006-08-25 17:25:49 +000033</tr>
34</table>
35</div>
36<!-- END NAVIGATION -->
37
38
39<!-- START BREADCRUMB -->
40<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
41<tr>
42<td id="breadcrumb">
Derek Jones7a9193a2008-01-21 18:39:20 +000043<a href="http://codeigniter.com/">CodeIgniter Home</a> &nbsp;&#8250;&nbsp;
adminb0dd10f2006-08-25 17:25:49 +000044<a href="../index.html">User Guide Home</a> &nbsp;&#8250;&nbsp;
45Pagination Class
46</td>
Derek Allardbc030912007-06-24 18:25:29 +000047<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide&nbsp; <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" />&nbsp;<input type="submit" class="submit" name="sa" value="Go" /></form></td>
adminb0dd10f2006-08-25 17:25:49 +000048</tr>
49</table>
50<!-- END BREADCRUMB -->
51
52<br clear="all" />
53
54
55<!-- START CONTENT -->
56<div id="content">
57
58
59<h1>Pagination Class</h1>
60
Derek Allardcda47ee2007-04-26 21:30:35 +000061<p>CodeIgniter's Pagination class is very easy to use, and it is 100% customizable, either dynamically or via stored preferences.</p>
adminb0dd10f2006-08-25 17:25:49 +000062
63<p>If you are not familiar with the term "pagination", it refers to links that allows you to navigate from page to page, like this:</p>
64
65<code><a href="#">&laquo; First</a>&nbsp;&nbsp;<a href="#">&lt;</a>&nbsp;<a href="#">1</a>&nbsp;<a href="#">2</a>&nbsp;<b>3</b>&nbsp;<a href="#">4</a>&nbsp;<a href="#">5</a>&nbsp;<a href="#">&gt;</a>&nbsp;&nbsp;<a href="#">Last &raquo;</a></code>
66
67<h2>Example</h2>
68
69<p>Here is a simple example showing how to create pagination in one of your <a href="../general/controllers.html">controller</a> functions:</p>
70
71<code>
72$this->load->library('pagination');<br /><br />
73$config['base_url'] = 'http://www.your-site.com/index.php/test/page/';<br />
74$config['total_rows'] = '200';<br />
75$config['per_page'] = '20';
76<br /><br />
77$this->pagination->initialize($config);
78
79<br /><br />
80echo $this->pagination->create_links();</code>
81
82<h3>Notes:</h3>
83
admine334c472006-10-21 19:44:22 +000084<p>The <var>$config</var> array contains your configuration variables. It is passed to the <dfn>$this->pagination->initialize</dfn> function as shown above. Although there are some twenty items you can configure, at
adminb0dd10f2006-08-25 17:25:49 +000085minimum you need the three shown. Here is a description of what those items represent:</p>
86
87<ul>
88 <li><strong>base_url</strong> This is the full URL to the controller class/function containing your pagination. In the example
admin141808a2006-08-27 01:52:51 +000089 above, it is pointing to a controller called "Test" and a function called "page". Keep in mind that you can
adminb0dd10f2006-08-25 17:25:49 +000090 <a href="../general/routing.html">re-route your URI</a> if you need a different structure.</li>
91 <li><strong>total_rows</strong> This number represents the total rows in the result set you are creating pagination for.
92 Typically this number will be the total rows that your database query returned.
93 </li>
94 <li><strong>per_page</strong> The number of items you intend to show per page. In the above example, you would be showing 20 items per page.</li>
95</ul>
96
Derek Allardc6441282007-07-04 23:54:32 +000097<p>The <var>create_links()</var> function returns an empty string when there is no pagination to show.</p>
adminb0dd10f2006-08-25 17:25:49 +000098
99
100<h3>Setting preferences in a config file</h3>
101
102<p>If you prefer not to set preferences using the above method, you can instead put them into a config file.
103Simply create a new file called the <var>pagination.php</var>, add the <var>$config</var>
104array in that file. Then save the file in: <var>config/pagination.php</var> and it will be used automatically. You
105will NOT need to use the <dfn>$this->pagination->initialize</dfn> function if you save your preferences in a config file.</p>
106
107
108<h2>Customizing the Pagination</h2>
109
110<p>The following is a list of all the preferences you can pass to the initialization function to tailor the display.</p>
111
112
113<h4>$config['uri_segment'] = 3;</h4>
114
115<p>The pagination function automatically determines which segment of your URI contains the page number. If you need
116something different you can specify it.</p>
117
118<h4>$config['num_links'] = 2;</h4>
119
admine334c472006-10-21 19:44:22 +0000120<p>The number of "digit" links you would like before and after the selected page number. For example, the number 2
adminb0dd10f2006-08-25 17:25:49 +0000121will place two digits on either side, as in the example links at the very top of this page.</p>
122
123<h2>Adding Enclosing Markup</h2>
124
125<p>If you would like to surround the entire pagination with some markup you can do it with these two prefs:</p>
126
127<h4>$config['full_tag_open'] = '&lt;p>';</h4>
128<p>The opening tag placed on the left side of the entire result.</p>
129
130<h4>$config['full_tag_close'] = '&lt;/p>';</h4>
131<p>The closing tag placed on the right side of the entire result.</p>
132
133
134<h2>Customizing the First Link</h2>
135
136<h4>$config['first_link'] = 'First';</h4>
137<p>The text you would like shown in the "first" link on the left.</p>
138
139<h4>$config['first_tag_open'] = '&lt;div>';</h4>
140<p>The opening tag for the "first" link.</p>
141
Derek Allardce66d152008-03-04 20:55:55 +0000142<h4>$config['first_tag_close'] = '&lt;/div>';</h4>
adminb0dd10f2006-08-25 17:25:49 +0000143<p>The closing tag for the "first" link.</p>
144
145<h2>Customizing the Last Link</h2>
146
147<h4>$config['last_link'] = 'Last';</h4>
148<p>The text you would like shown in the "last" link on the right.</p>
149
150<h4>$config['last_tag_open'] = '&lt;div>';</h4>
151<p>The opening tag for the "last" link.</p>
152
Derek Allardce66d152008-03-04 20:55:55 +0000153<h4>$config['last_tag_close'] = '&lt;/div>';</h4>
adminb0dd10f2006-08-25 17:25:49 +0000154<p>The closing tag for the "last" link.</p>
155
156<h2>Customizing the "Next" Link</h2>
157
158<h4>$config['next_link'] = '&amp;gt';</h4>
159<p>The text you would like shown in the "next" page link.</p>
160
161<h4>$config['next_tag_open'] = '&lt;div>';</h4>
162<p>The opening tag for the "next" link.</p>
163
Derek Allardce66d152008-03-04 20:55:55 +0000164<h4>$config['next_tag_close'] = '&lt;/div>';</h4>
adminb0dd10f2006-08-25 17:25:49 +0000165<p>The closing tag for the "next" link.</p>
166
167<h2>Customizing the "Previous" Link</h2>
168
169<h4>$config['prev_link'] = '&amp;lt';</h4>
170<p>The text you would like shown in the "previous" page link.</p>
171
172<h4>$config['prev_tag_open'] = '&lt;div>';</h4>
173<p>The opening tag for the "previous" link.</p>
174
Derek Allardce66d152008-03-04 20:55:55 +0000175<h4>$config['prev_tag_close'] = '&lt;/div>';</h4>
adminb0dd10f2006-08-25 17:25:49 +0000176<p>The closing tag for the "previous" link.</p>
177
178<h2>Customizing the "Current Page" Link</h2>
179
180<h4>$config['cur_tag_open'] = '&lt;b>';</h4>
181<p>The opening tag for the "current" link.</p>
182
Derek Allardce66d152008-03-04 20:55:55 +0000183<h4>$config['cur_tag_close'] = '&lt;/b>';</h4>
adminb0dd10f2006-08-25 17:25:49 +0000184<p>The closing tag for the "current" link.</p>
185
186
187<h2>Customizing the "Digit" Link</h2>
188
189<h4>$config['num_tag_open'] = '&lt;div>';</h4>
190<p>The opening tag for the "digit" link.</p>
191
Derek Allardce66d152008-03-04 20:55:55 +0000192<h4>$config['num_tag_close'] = '&lt;/div>';</h4>
adminb0dd10f2006-08-25 17:25:49 +0000193<p>The closing tag for the "digit" link.</p>
194
195
196
197</div>
198<!-- END CONTENT -->
199
200
201<div id="footer">
202<p>
203Previous Topic:&nbsp;&nbsp;<a href="output.html">Output Class</a>
204&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
205<a href="#top">Top of Page</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
206<a href="../index.html">User Guide Home</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
207Next Topic:&nbsp;&nbsp;<a href="sessions.html">Session Class</a>
Derek Allardc6441282007-07-04 23:54:32 +0000208</p>
Derek Jones07870432008-02-13 03:49:26 +0000209<p><a href="http://codeigniter.com">CodeIgniter</a> &nbsp;&middot;&nbsp; Copyright &#169; 2006-2008 &nbsp;&middot;&nbsp; <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
adminb0dd10f2006-08-25 17:25:49 +0000210</div>
211
212</body>
213</html>