@@ -32,11 +32,83 @@ Load the component in a controller's `initialize()` method:
32
32
``` php
33
33
public function initialize()
34
34
{
35
- parent::initialize();
36
- $this->loadComponent('BryanCrowe/ApiPagination.ApiPagination');
35
+ parent::initialize();
36
+ $this->loadComponent('BryanCrowe/ApiPagination.ApiPagination');
37
37
}
38
38
```
39
39
40
+ Your responses will now contain the pagination information, and will look
41
+ something like:
42
+
43
+ ``` json
44
+ {
45
+ "articles" : [" ..." , " ..." , " ..." ],
46
+ "pagination" : {
47
+ "finder" : " all" ,
48
+ "page" : 1 ,
49
+ "current" : 20 ,
50
+ "count" : 5000 ,
51
+ "perPage" : 20 ,
52
+ "prevPage" : false ,
53
+ "nextPage" : true ,
54
+ "pageCount" : 250 ,
55
+ "sort" : null ,
56
+ "direction" : false ,
57
+ "limit" : null ,
58
+ "sortDefault" : false ,
59
+ "directionDefault" : false
60
+ }
61
+ }
62
+ ```
63
+
64
+ ### Configuring the Pagination Ouput
65
+
66
+ ApiPagination has three keys for configuration: ` key ` , ` aliases ` , and ` visible ` .
67
+
68
+ The ` key ` configuration key allows you to change the name of the pagination key.
69
+ For instance, if you wanted to change "pagination" to "paging".
70
+
71
+ The ` aliases ` configuration key allows you to change names of the pagination
72
+ keys. For instance, if you wanted to change "page" to "currentPage".
73
+
74
+ The ` visible ` confiration key allows you to set which pagination keys will be
75
+ visible in your rendered response.
76
+
77
+ An example using all these configuration keys:
78
+
79
+ ``` php
80
+ $this->loadComponent('BryanCrowe/ApiPagination.ApiPagination', [
81
+ 'key' => 'paging',
82
+ 'aliases' => [
83
+ 'page' => 'currentPage',
84
+ 'current' => 'resultCount'
85
+ ],
86
+ 'visible' => [
87
+ 'currentPage',
88
+ 'resultCount',
89
+ 'prevPage',
90
+ 'nextPage'
91
+ ]
92
+ ]);
93
+ ```
94
+
95
+ This configuration would yield:
96
+
97
+ ``` json
98
+ {
99
+ "articles" : [" ..." , " ..." , " ..." ],
100
+ "paging" : {
101
+ "prevPage" : false ,
102
+ "nextPage" : true ,
103
+ "currentPage" : 1 ,
104
+ "resultCount" : 20
105
+ }
106
+ }
107
+ ```
108
+
109
+ ** Note:** Whenever setting key visibily, use the aliased name if you've given it
110
+ one.
111
+
40
112
## Change log
41
113
42
114
Please see [ CHANGELOG] ( CHANGELOG.md ) for more information what has changed recently.
0 commit comments