You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/book/v3/advanced.md
+17-61Lines changed: 17 additions & 61 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
laminas-paginator ships with a plugin manager for adapters, `Laminas\Paginator\AdapterPluginManager`.
6
6
The plugin manager can be used to retrieve adapters.
7
-
Since most adapters require constructor arguments, they may be passed as the second argument to the `get()` method in the same order they appear in the constructor.
7
+
Since most adapters require constructor arguments, they may be passed as the second argument to the `build()` method in the same order they appear in the constructor.
8
8
9
9
### Examples
10
10
@@ -15,42 +15,37 @@ use Laminas\Paginator\AdapterPluginManager;
At some point you may run across a data type that is not covered by the packaged
27
-
adapters. In this case, you will need to write your own.
26
+
At some point you may run across a data type that is not covered by the packaged adapters.
27
+
In this case, you will need to write your own.
28
28
29
-
To do so, you must implement `Laminas\Paginator\Adapter\AdapterInterface`. There
30
-
are two methods required to do this:
29
+
To do so, you must implement `Laminas\Paginator\Adapter\AdapterInterface`.
30
+
There are two methods required to do this:
31
31
32
-
-`count(): int`
33
-
-`getItems(int $offset, int $itemCountPerPage) | array`
32
+
-`count(): int`
33
+
-`getItems(int $offset, int $itemCountPerPage): iterable`
34
34
35
-
Additionally, you'll typically implement a constructor that takes your data
36
-
source as a parameter.
35
+
Additionally, you'll typically implement a constructor that takes your data source as a parameter.
37
36
38
-
If you've ever used the SPL interface [Countable](http://php.net/Countable),
39
-
you're familiar with `count()`. As used with laminas-paginator, this is the total
40
-
number of items in the data collection; `Laminas\Paginator\Paginator::countAllItems`
41
-
proxies to this method.
37
+
If you've ever used the SPL interface [Countable](http://php.net/Countable), you're familiar with `count()`.
38
+
As used with `laminas-paginator`, this is the total number of items in the data collection; `Laminas\Paginator\Paginator::countAllItems` proxies to this method.
42
39
43
-
When retrieving items for the current page, `Laminas\Paginator\Paginator` calls on
44
-
your adapter's `getItems()` method, providing it with an offset and the number
45
-
of items to display per page; your job is to return the appropriate slice of
46
-
data. For an array, that would be:
40
+
When retrieving items for the current page, `Laminas\Paginator\Paginator` calls on your adapter's `getItems()` method, providing it with an offset and the number of items to display per page;
41
+
your job is to return the appropriate slice of data.
`setCurrentPageNumber(int $page) : void` | Sets the current page number (default 1).
8
-
`setItemCountPerPage(int $count) : void` | Sets the maximum number of items to display on a page (default 10).
9
-
`setPageRange(int $range) : void` | Sets the number of items to display in the pagination control (default 10). Note: Most of the time this number will be adhered to exactly, but scrolling styles do have the option of only using it as a guideline or starting value (e.g., Elastic).
5
+
It is perfectly possible to use Paginator without using Laminas Service Manager as the DIC in your project, but some convenience will be sacrificed.
6
+
7
+
## Configuring Pagination Defaults
8
+
9
+
The following configuration would be returned as part of the `config` service returned from the DI container, so it would be inserted into a PHP file that is autoloaded during bootstrap, or in a `ConfigProvider` perhaps:
10
+
11
+
```php
12
+
return [
13
+
'paginator' => [
14
+
'itemCountPerPage' => 10,
15
+
'pageRange' => 10,
16
+
'scrollingStyle' => 'Sliding',
17
+
],
18
+
];
19
+
```
20
+
21
+
The above configures the default page size to 10, the default page range to 10 and uses the `Sliding` scrolling style by default.
22
+
23
+
## The Paginator Factory Service
24
+
25
+
In order for these defaults to apply to newly created paginators, you must use the `PaginatorFactory` service to delegate construction of your paginators:
26
+
27
+
### Create a Paginator by Providing a Concrete Adapter
// The paginator above will now be configured with the defaults you have specified.
36
+
```
37
+
38
+
By using the `PaginatorFactory`, you can ensure consistent configuration of paginators across your application with a single place where these defaults can be changed, instead of hard-coding preferences into every call to `new Paginator(...)`.
39
+
40
+
The factory has 2 more methods for building paginators:
41
+
42
+
### Create a Paginator by Providing Configuration for an Adapter
0 commit comments