blob: f1653c913ad40f7cc351b27212eaa3b5af94f1ed [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001################
2Pagination Class
3################
4
5CodeIgniter's Pagination class is very easy to use, and it is 100%
6customizable, either dynamically or via stored preferences.
7
8If you are not familiar with the term "pagination", it refers to links
9that allows you to navigate from page to page, like this::
10
11 « First  < 1 2 3 4 5 >  Last »
12
13*******
14Example
15*******
16
17Here is a simple example showing how to create pagination in one of your
18:doc:`controller <../general/controllers>` functions::
19
Derek Jones36be9692011-10-05 15:52:41 -050020 $this->load->library('pagination');
21
22 $config['base_url'] = 'http://example.com/index.php/test/page/';
23 $config['total_rows'] = 200;
24 $config['per_page'] = 20;
25
26 $this->pagination->initialize($config);
27
28 echo $this->pagination->create_links();
Derek Jones8ede1a22011-10-05 13:34:52 -050029
30Notes
31=====
32
33The $config array contains your configuration variables. It is passed to
34the $this->pagination->initialize function as shown above. Although
35there are some twenty items you can configure, at minimum you need the
36three shown. Here is a description of what those items represent:
37
38- **base_url** This is the full URL to the controller class/function
39 containing your pagination. In the example above, it is pointing to a
40 controller called "Test" and a function called "page". Keep in mind
41 that you can :doc:`re-route your URI <../general/routing>` if you
42 need a different structure.
43- **total_rows** This number represents the total rows in the result
44 set you are creating pagination for. Typically this number will be
45 the total rows that your database query returned.
46- **per_page** The number of items you intend to show per page. In the
47 above example, you would be showing 20 items per page.
48
49The create_links() function returns an empty string when there is no
50pagination to show.
51
52Setting preferences in a config file
53====================================
54
55If you prefer not to set preferences using the above method, you can
56instead put them into a config file. Simply create a new file called
57pagination.php, add the $config array in that file. Then save the file
58in: config/pagination.php and it will be used automatically. You will
59NOT need to use the $this->pagination->initialize function if you save
60your preferences in a config file.
61
62**************************
63Customizing the Pagination
64**************************
65
66The following is a list of all the preferences you can pass to the
67initialization function to tailor the display.
68
69$config['uri_segment'] = 3;
70============================
71
72The pagination function automatically determines which segment of your
73URI contains the page number. If you need something different you can
74specify it.
75
76$config['num_links'] = 2;
77==========================
78
79The number of "digit" links you would like before and after the selected
80page number. For example, the number 2 will place two digits on either
81side, as in the example links at the very top of this page.
82
83$config['use_page_number'] = TRUE;
84==================================
85
86By default, the URI segment will use the starting index for the items
87you are paginating. If you prefer to show the the actual page number,
88set this to TRUE.
89
90$config['page_query_string'] = TRUE;
91====================================
92
93By default, the pagination library assume you are using :doc:`URI
94Segments <../general/urls>`, and constructs your links something
95like
96
97::
98
99 http://example.com/index.php/test/page/20
100
101
102If you have $config['enable_query_strings'] set to TRUE your links
103will automatically be re-written using Query Strings. This option can
104also be explictly set. Using $config['page_query_string'] set to TRUE,
105the pagination link will become.
106
107::
108
109 http://example.com/index.php?c=test&m=page&per_page=20
110
111
112Note that "per_page" is the default query string passed, however can be
113configured using $config['query_string_segment'] = 'your_string'
114
115***********************
116Adding Enclosing Markup
117***********************
118
119If you would like to surround the entire pagination with some markup you
120can do it with these two prefs:
121
122$config['full_tag_open'] = '<p>';
123===================================
124
125The opening tag placed on the left side of the entire result.
126
127$config['full_tag_close'] = '</p>';
128=====================================
129
130The closing tag placed on the right side of the entire result.
131
132**************************
133Customizing the First Link
134**************************
135
136$config['first_link'] = 'First';
137=================================
138
139The text you would like shown in the "first" link on the left. If you do
140not want this link rendered, you can set its value to FALSE.
141
142$config['first_tag_open'] = '<div>';
143======================================
144
145The opening tag for the "first" link.
146
147$config['first_tag_close'] = '</div>';
148========================================
149
150The closing tag for the "first" link.
151
152*************************
153Customizing the Last Link
154*************************
155
156$config['last_link'] = 'Last';
157===============================
158
159The text you would like shown in the "last" link on the right. If you do
160not want this link rendered, you can set its value to FALSE.
161
162$config['last_tag_open'] = '<div>';
163=====================================
164
165The opening tag for the "last" link.
166
167$config['last_tag_close'] = '</div>';
168=======================================
169
170The closing tag for the "last" link.
171
172***************************
173Customizing the "Next" Link
174***************************
175
176$config['next_link'] = '&gt;';
177===============================
178
179The text you would like shown in the "next" page link. If you do not
180want this link rendered, you can set its value to FALSE.
181
182$config['next_tag_open'] = '<div>';
183=====================================
184
185The opening tag for the "next" link.
186
187$config['next_tag_close'] = '</div>';
188=======================================
189
190The closing tag for the "next" link.
191
192*******************************
193Customizing the "Previous" Link
194*******************************
195
196$config['prev_link'] = '&lt;';
197===============================
198
199The text you would like shown in the "previous" page link. If you do not
200want this link rendered, you can set its value to FALSE.
201
202$config['prev_tag_open'] = '<div>';
203=====================================
204
205The opening tag for the "previous" link.
206
207$config['prev_tag_close'] = '</div>';
208=======================================
209
210The closing tag for the "previous" link.
211
212***********************************
213Customizing the "Current Page" Link
214***********************************
215
216$config['cur_tag_open'] = '<b>';
217==================================
218
219The opening tag for the "current" link.
220
221$config['cur_tag_close'] = '</b>';
222====================================
223
224The closing tag for the "current" link.
225
226****************************
227Customizing the "Digit" Link
228****************************
229
230$config['num_tag_open'] = '<div>';
231====================================
232
233The opening tag for the "digit" link.
234
235$config['num_tag_close'] = '</div>';
236======================================
237
238The closing tag for the "digit" link.
239
240****************
241Hiding the Pages
242****************
243
244If you wanted to not list the specific pages (for example, you only want
245"next" and "previous" links), you can suppress their rendering by
246adding::
247
248 $config['display_pages'] = FALSE;
249
250******************************
251Adding a class to every anchor
252******************************
253
254If you want to add a class attribute to every link rendered by the
255pagination class, you can set the config "anchor_class" equal to the
256classname you want.