-
Notifications
You must be signed in to change notification settings - Fork 232
/
Copy pathpagination.html
960 lines (917 loc) · 30.4 KB
/
pagination.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./../assets/css/combined.css?20170912">
<link rel="shortcut icon" href="./../favicon.ico" />
<script src="https://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
var path = './../';
var class_prefix = "Pagination::";
</script>
<script src="./../assets/js/combined.js?20170912"></script>
<title>Pagination - Classes - FuelPHP Documentation</title>
</head>
<body>
<div id="container">
<header id="header">
<div class="table">
<div id="cse">
<gcse:searchbox-only newWindow="true"></gcse:searchbox-only>
</div>
<h1>
<a href="https://fuelphp.com"><img height="37px" width="147px" src="./../assets/img/fuel.png" /></a>
<strong>Documentation</strong>
</h1>
</div>
<nav>
<div class="clear"></div>
</nav>
<a href="#" id="toc_handle">table of contents</a>
<div class="clear"></div>
</header>
<div id="main">
<h2>Pagination Class</h2>
<p>The pagination class allows you to easily setup pagination for records you display.</p>
<section>
<p>Simple examples on how to use the Pagination class . You can put this inside your action methods in your controller.</p>
<h3 id="how_to_query_builder">How To Paginate with the Query Builder</h3>
<pre class="php"><code>$config = array(
'pagination_url' => 'http://localhost/fuel/welcome/index/',
'total_items' => 10,
'per_page' => 5,
'uri_segment' => 3,
// or if you prefer pagination by query string
//'uri_segment' => 'page',
);
// Create a pagination instance named 'mypagination'
$pagination = Pagination::forge('mypagination', $config);
$data['example_data'] = DB::select('id', 'value')
->from('pagination')
->limit($pagination->per_page)
->offset($pagination->offset)
->execute()
->as_array();
// we pass the object, it will be rendered when echo'd in the view
$data['pagination'] = $pagination;
// return the view
return \View::forge('welcome/index', $data);</code></pre>
<h3 id="how_to_orm">How To Paginate with ORM</h3>
<pre class="php"><code>$config = array(
'pagination_url' => 'http://localhost/fuel/posts/index/',
'total_items' => Model_Post::count(),
'per_page' => 10,
'uri_segment' => 3,
// or if you prefer pagination by query string
//'uri_segment' => 'page',
);
$pagination = Pagination::forge('mypagination', $config);
$data['example_data'] = Model_Post::query()
->rows_offset($pagination->offset)
->rows_limit($pagination->per_page)
->get();
// we pass the object, it will be rendered when echo'd in the view
$data['pagination'] = $pagination;
// return the view
return \View::forge('posts/index', $data);</code></pre>
</section>
<section>
<h3 id="configuration">Configuration</h3>
<p>
You can configure the pagination instance in several ways. You can pass an array with the configuration when you
<kbd>forge</kbd> the instance, or you can update the properties directly on the instance.
</p>
<p>The following configuration settings can be defined:</p>
<table class="config">
<tbody>
<tr class="header">
<th>Param</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
<tr>
<th>pagination_url</th>
<td>string</td>
<td><pre class="php"><code>null</code></pre></td>
<td>
The URL of page where you have pagination. If null, Fuel tries to detect it from the current URL.
</td>
</tr>
<tr>
<th>uri_segment</th>
<td>integer|string</td>
<td><pre class="php"><code>3</code></pre></td>
<td>
The URI segment containing the page number (if integer). The query string field containing the page number (if string).
</td>
</tr>
<tr>
<th>num_links</th>
<td>integer</td>
<td><pre class="php"><code>5</code></pre></td>
<td>
The total number of links to show.
</td>
</tr>
<tr>
<th>total_items</th>
<td>integer</td>
<td><pre class="php"><code>0</code></pre></td>
<td>
The total number of items. Usually this is the result of a count() query.
</td>
</tr>
<tr>
<th>per_page</th>
<td>integer</td>
<td><pre class="php"><code>10</code></pre></td>
<td>
The number of items per page.
</td>
</tr>
<tr>
<th>current_page</th>
<td>integer</td>
<td><pre class="php"><code>null</code></pre></td>
<td>
The page to load if no page number is present in the URI. If not given, it defaults to 'default_page'.
</td>
</tr>
<tr>
<th>show_first</th>
<td>bool</td>
<td><pre class="php"><code>false</code></pre></td>
<td>
Generates a 'to the first page' link if true and not already on the first page.
</td>
</tr>
<tr>
<th>show_last</th>
<td>bool</td>
<td><pre class="php"><code>false</code></pre></td>
<td>
Generates a 'to the last page' link if true and not already on the last page.
</td>
</tr>
<tr>
<th>link_offset</th>
<td>int / float</td>
<td><pre class="php"><code>0.50</code></pre></td>
<td>
Offset of the active link in the pagination block, either in a decimal between 0 and 1, or in an integer (precentage) between 0 and 100.
</td>
</tr>
<tr>
<th>default_page</th>
<td>mixed</td>
<td><pre class="php"><code>'first'</code></pre></td>
<td>
The page to load if no page number is present in the URI. Valid are 'first', 'last' or a page number. If not given, it defaults to 'first'.
</td>
</tr>
</tbody>
</table>
</section>
<section>
<h3 id="linkoffsets">Link offsets</h3>
<p>
By default, the Pagination class will try to position the active link (the one for the current page) in the middle of the pagination
block.
</p>
<p>
You can control this behaviour using the <kbd>link_offset</kbd> value in the configuration. This value is defined either by a
float between 0 and 1, or by an integer between 0 and 100 (like a percentage). By default this value is set to <code>0.5</code> (= 50%).
If you make the value smaller, the active link will move to the left, if you make the value bigger, the active link will move
to the right.
</p>
<h5 id="linkoffsetexample">Example</h5>
<p>
Let's assume you have a total of 20 pages you can display. You have set <kbd>num_links</kbd> to 5, displaying links for 5 pages
in total, and you're displaying previous and next links as well. The page you have currently selected is page 6.
</p>
<ul>
<li>
With the default setting of <kbd>0.5</kbd>, <blockquote><code>«</code> <code>4</code> <code>5</code> 6 <code>7</code> <code>8</code> <code>»</code></blockquote> is displayed, keeping
the selected page 6 nicely in the middle of the block.
</li>
<li>
When you change the setting to <kbd>0</kbd>, Pagination will always try to make the first link the active link. In this case,
<blockquote><code>«</code> 6 <code>7</code> <code>8</code> <code>9</code> <code>10</code> <code>»</code></blockquote>
is being displayed, making the selected page 6 the first link in the block.
</li>
<li>
If you would change the setting to <kbd>1</kbd>, Pagination will always try to make the last link the active link. In this case,
<blockquote><code>«</code> <code>2</code> <code>3</code> <code>4</code> <code>5</code> 6 <code>»</code></blockquote>
will be displayed.
</li>
</ul>
<p>
You can use any value in the range, to progressively shift the active focus either left or right. Obviously, the more links you
display, the more granular you can shift the focus.
</p>
<p class="note">
This only works if there are enough pages to do so. If you only have 5 pages available, you want to display 5 links, and page 3 is the
current page, no previous and next links are displayed, and the current page will be in the middle, no matter what the setting of
<kbd>link_offset</kbd> is. There are simply not enough pages available to move the current page link left or right.
</p>
</section>
<section>
<h3 id="templating">Templating</h3>
<p>
Every pagination instance uses a template to generate the HTML needed to create the pagination markup.
You can store your standard templates in the <em>config/pagination.php</em> file. Copy the file from the
core config folder to your app config folder before you make any modifications. The default configuration
file comes with three templates, the FuelPHP default, and a Twitter Bootstrap v2 and v3 compatible template.
</p>
<p>The following template entries must be defined:</p>
<table class="config">
<tbody>
<tr>
<th>wrapper</th>
<td>string</td>
<td><pre class="html"><code><div class="pagination">\n\t{pagination}\n</div>\n</code></pre></td>
<td>
Markup that will wrap the generated pagination markup.
</td>
</tr>
<tr>
<th>first</th>
<td>string</td>
<td><pre class="html"><code><span class="first">\n\t{link}\n</span>\n</code></pre></td>
<td>
Markup that will be used to generate the first page markup.
</td>
</tr>
<tr>
<th>first-inactive</th>
<td>string</td>
<td>none</td>
<td>
Markup that will be used to generate the first page markup, if this page is first or single.
</td>
</tr>
<tr>
<th>first-inactive-link</th>
<td>string</td>
<td>none</td>
<td>
Markup that will be used to generate the first page link, if this page is first or single.
</td>
</tr>
<tr>
<th>first-marker</th>
<td>string</td>
<td><pre class="html"><code>&laquo;&laquo;</code></pre></td>
<td>
Markup that will be used to generate the marker of first page.
</td>
</tr>
<tr>
<th>first-link</th>
<td>string</td>
<td><pre class="html"><code>\t\t<a href="{uri}">{page}</a>\n</code></pre></td>
<td>
Markup that will be used to generate the first page link.
</td>
</tr>
<tr>
<th>previous</th>
<td>string</td>
<td><pre class="html"><code><span class="previous">\n\t{link}\n</span>\n</code></pre></td>
<td>
Markup that will be used to generate the previous page markup.
</td>
</tr>
<tr>
<th>previous-marker</th>
<td>string</td>
<td><pre class="html"><code>&laquo;</code></pre></td>
<td>
Markup that will be used to generate the marker of previous page.
</td>
</tr>
<tr>
<th>previous-link</th>
<td>string</td>
<td><pre class="html"><code>\t\t<a href="{uri}" rel="prev">{page}</a>\n</code></pre></td>
<td>
Markup that will be used to generate the previous page link.
</td>
</tr>
<tr>
<th>previous-inactive</th>
<td>string</td>
<td><pre class="html"><code><span class="previous-inactive">\n\t{link}\n</span>\n</code></pre></td>
<td>
Markup that will be used to generate the previous page markup for inactive links.
</td>
</tr>
<tr>
<th>previous-inactive-link</th>
<td>string</td>
<td><pre class="html"><code>\t\t<a href="{uri}" rel="prev">{page}</a>\n</code></pre></td>
<td>
Markup that will be used to generate the previous page markup for inactive links.
</td>
</tr>
<tr>
<th>regular</th>
<td>string</td>
<td><pre class="html"><code><span>\n\t{link}\n</span>\n</code></pre></td>
<td>
Markup that will be used to generate the markup for other pages.
</td>
</tr>
<tr>
<th>regular-link</th>
<td>string</td>
<td><pre class="html"><code>\t\t<a href="{uri}">{page}</a>\n</code></pre></td>
<td>
Markup that will be used to generate the markup for other page links.
</td>
</tr>
<tr>
<th>active</th>
<td>string</td>
<td><pre class="html"><code><span class="active">\n\t{link}\n</span>\n</code></pre></td>
<td>
Markup that will be used to generate the markup for the current page.
</td>
</tr>
<tr>
<th>active-link</th>
<td>string</td>
<td><pre class="html"><code>\t\t<a href="{uri}">{page}</a>\n</code></pre></td>
<td>
Markup that will be used to generate the markup for the link to the current page.
</td>
</tr>
<tr>
<th>next</th>
<td>string</td>
<td><pre class="html"><code><span class="next">\n\t{link}\n</span>\n</code></pre></td>
<td>
Markup that will be used to generate the next page markup.
</td>
</tr>
<tr>
<th>next-marker</th>
<td>string</td>
<td><pre class="html"><code>&raquo;</code></pre></td>
<td>
Markup that will be used to generate the marker of next page.
</td>
</tr>
<tr>
<th>next-link</th>
<td>string</td>
<td><pre class="html"><code>\t\t<a href="{uri}" rel="next">{page}</a>\n</code></pre></td>
<td>
Markup that will be used to generate the next page link.
</td>
</tr>
<tr>
<th>next-inactive</th>
<td>string</td>
<td><pre class="html"><code><span class="next-inactive">\n\t{link}\n</span>\n</code></pre></td>
<td>
Markup that will be used to generate the next page markup for inactive links.
</td>
</tr>
<tr>
<th>next-inactive-link</th>
<td>string</td>
<td><pre class="html"><code>\t\t<a href="{uri}" rel="next">{page}</a>\n</code></pre></td>
<td>
Markup that will be used to generate the next page link for inactive links.
</td>
</tr>
<tr>
<th>last</th>
<td>string</td>
<td><pre class="html"><code><span class="last">\n\t{link}\n</span>\n</code></pre></td>
<td>
Markup that will be used to generate the last page markup.
</td>
</tr>
<tr>
<th>last-marker</th>
<td>string</td>
<td><pre class="html"><code>&raquo;&raquo;</code></pre></td>
<td>
Markup that will be used to generate the marker of last page.
</td>
</tr>
<tr>
<th>last-link</th>
<td>string</td>
<td><pre class="html"><code>\t\t<a href="{uri}">{page}</a>\n</code></pre></td>
<td>
Markup that will be used to generate the last page link.
</td>
</tr>
<tr>
<th>last-inactive</th>
<td>string</td>
<td>none</td>
<td>
Markup that will be used to generate the last page markup, if this page is last or single.
</td>
</tr>
<tr>
<th>last-inactive-link</th>
<td>string</td>
<td>none</td>
<td>
Markup that will be used to generate the last page link, if this page is last or single.
</td>
</tr>
</tbody>
</table>
<p>
In the template, <strong>{uri}</strong> will be replaced by the generated pagination link
(by <strong>#</strong> if inactive template), and <strong>{page}</strong> by the page number
or the previous / next marker. If you want to use an image for these markers, just modify the corresponding
link definitions in the template, replacing <strong>{page}</strong> by the markup for the image.
</p>
<p class="note">
The configuration you pass when you forge the pagination instance will be merged with the default
template defined in your configuration file. This will allow you to only pass the values you want
to override. If your template in the configuration file is not complete, the default values as
mentioned above will be used.
</p>
</section>
<section>
<article>
<h4 class="method" id="method_forge">forge($name = 'default', $config = array())</h4>
<p>The <strong>forge</strong> method allows you to create a new pagination instance, and configure it by passing an array.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$name</kbd></th>
<td><i>Required</i></td>
<td>The name of the instance to be created. If no name is given, the 'default' instance is created.</td>
</tr>
<tr>
<th><kbd>$config</kbd></th>
<td><pre class="php"><code>array()</code></pre></td>
<td>The configuration array.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>Pagination</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>// create a new pagination instance
$pagination = Pagination::forge('mypagination', array(
'pagination_url' => 'http://docs.fuelphp.com/',
'uri_segment' => 2,
'total_items' => 10,
'per_page' => 20,
));</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_instance">instance($name = null)</h4>
<p>The <strong>instance</strong> method allows you retrieve a previously forged instance, or return the default instance if no name was given.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$name</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>The name of the instance to be returned. If no name is given, the 'default' instance is created.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>mixed. a Pagination object, or false if the requested instance does not exist.</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>// fetch the previously forged instance
$pagination = Pagination::instance('mypagination');</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_render">render($raw = false)</h4>
<p>The <strong>render</strong> method generates the markup to display the pagination links in the view.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>No</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$raw</kbd></th>
<td><pre class="php"><code>false</code></pre></td>
<td>If true, an array with raw pagination data is returned instead of the rendered pagination markup.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>// fetch a previously forged instance, and render it
echo Pagination::instance('mypagination')->render();</code></pre>
</td>
</tr>
</tbody>
</table>
<p class="note">
The pagination object contains an __toString() method, that will cause the render() method to be called
when you echo the object, or cast it to string.
</p>
</article>
<article>
<h4 class="method" id="method_first">first($marker = null)</h4>
<p>
The <strong>first</strong> method generates the markup to display a "First page" link for pagination.
If no string is given to be used as marker, the "first-marker" value from the template will be used.
</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>No</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$marker</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>The text to be displayed in the link. Defaults to the 'first-marker' template value.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>// fetch a previously forged instance, and render the "first page" link
echo Pagination::instance('mypagination')->first();</code></pre>
</td>
</tr>
</tbody>
</table>
<p class="note">
The "First page" link will only be shown if there is a first page, and you're not already on it.
Note that by default there is no inactive link defined for 'first'.
</p>
</article>
<article>
<h4 class="method" id="method_previous">previous($marker = null)</h4>
<p>
The <strong>previous</strong> method generates the markup to display a "Previous" link for pagination.
If no string is given to be used as marker, the "previous-marker" value from the template will be used.
</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>No</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$marker</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>The text to be displayed in the link. Defaults to the 'previous-marker' template value.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>// fetch a previously forged instance, and render the "previous page" link
echo Pagination::instance('mypagination')->previous();</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_next">next($marker = null)</h4>
<p>
The <strong>next</strong> method generates the markup to display a "Next" link for pagination.
If no string is given to be used as marker, the "next-marker" value from the template will be used.
</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>No</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$marker</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>The text to be displayed in the link. Defaults to the 'next-marker' template value.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>// fetch a previously forged instance, and render the "next page" link
echo Pagination::instance('mypagination')->next();</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_last">last($marker = null)</h4>
<p>
The <strong>last</strong> method generates the markup to display a "Last page" link for pagination.
If no string is given to be used as marker, the "last-marker" value from the template will be used.
</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>No</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$marker</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>The text to be displayed in the link. Defaults to the 'last-marker' template value.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>// fetch a previously forged instance, and render the "last page" link
echo Pagination::instance('mypagination')->last();</code></pre>
</td>
</tr>
</tbody>
</table>
<p class="note">
The "Last page" link will only be shown if there are any pages, and you're not already on the last one.
Note that by default there is no inactive link defined for 'last'.
</p>
</article>
<article>
<h4 class="method" id="method_pages_render">pages_render()</h4>
<p>The <strong>pages_render</strong> method generates the markup that displays the page links between previous and next links for pagination.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>No</td>
</tr>
<tr>
<th>Parameters</th>
<td>None</td>
</tr>
<tr>
<th>Returns</th>
<td>mixed</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>// fetch a previously forged instance, and render the "pages" link
echo Pagination::instance('mypagination')->pages_render();</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
</section>
<section>
<h3 id="static">Static interface</h3>
<p>
For your convinience, the Pagination class also has a static interface that operates on the default
instance only.
</p>
<article>
<h4 class="method" id="method_get">get($name)</h4>
<p>The <strong>get</strong> method allows you to get a configuration item on the default instance.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$name</kbd></th>
<td>Required</td>
<td>The name of the property to fetch.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>mixed, properly value, or <kbd>null</kbd> if the property doesn't exist.</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>// fetch the current page number
$page_number = Pagination::get('current_page');
// this is an alias of
$page_number = Pagination::instance()->current_page;</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_set">set($name, $value)</h4>
<p>The <strong>set</strong> method allows you to set a configuration item on the default instance to the given value.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$name</kbd></th>
<td>Required</td>
<td>The name of the property to set.</td>
</tr>
<tr>
<th><kbd>$value</kbd></th>
<td>Required</td>
<td>The value to set the property to.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>void</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>// set the total number of rows
$page_number = Pagination::set('total_items', 610);
// this is an alias of
Pagination::instance()->total_items = 610;</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<p class="note">
For backward compatibility, the static methods <kbd>set_config()</kbd>, <kbd>create_links()</kbd>,
<kbd>next_link()</kbd> and <kbd>prev_link()</kbd> will be emulated on the default instance, minimizing
the migration effort needed when upgrading an existing application to FuelPHP v1.4+.
</p>
<p>Note that there is no possible way to emulate direct access to static class properties at the moment,
so if your application uses that, you'll have to change them:</p>
<pre class="php"><code>// pre v1.4 usage:
Pagination::$per_page = 10;
// new usage:
Pagination::set('per_page', 10);
// pre v1.4 usage:
Model_Article::find()
->order_by('date', 'ASC')
->rows_offset(\Pagination::$offset)
->rows_limit(\Pagination::$per_page)
->get();
// new usage:
Model_Article::query()
->order_by('date', 'ASC')
->rows_offset(\Pagination::get('offset'))
->rows_limit(\Pagination::get('per_page'))
->get();
</code></pre>
</section>
</div>
<footer>
<p>
© FuelPHP Development Team 2010-2025 - <a href="https://fuelphp.com">FuelPHP</a> is released under the MIT license.
</p>
</footer>
</div>
</body>
</html>