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