Skip to content

Commit d0c6688

Browse files
committed
Add additional usage docs in the README
1 parent 4924318 commit d0c6688

File tree

1 file changed

+74
-2
lines changed

1 file changed

+74
-2
lines changed

README.md

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,83 @@ Load the component in a controller's `initialize()` method:
3232
``` php
3333
public function initialize()
3434
{
35-
parent::initialize();
36-
$this->loadComponent('BryanCrowe/ApiPagination.ApiPagination');
35+
parent::initialize();
36+
$this->loadComponent('BryanCrowe/ApiPagination.ApiPagination');
3737
}
3838
```
3939

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+
40112
## Change log
41113

42114
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

0 commit comments

Comments
 (0)