Skip to content

Commit 7c8144e

Browse files
authored
Merge pull request #2901 from jlamim/user_guide
Added information about the new features of the Pagination library
2 parents 73d6ae6 + e20b046 commit 7c8144e

1 file changed

Lines changed: 66 additions & 8 deletions

File tree

user_guide_src/source/libraries/pagination.rst

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ Within the view, we then need to tell it where to display the resulting links::
5757
And that's all it takes. The Pager class will render First and Last page links, as well as Next and Previous links
5858
for any pages more than two pages on either side of the current page.
5959

60+
It is important to be aware that the library pattern for Next and Previous is different from what is used in the traditional way of paging results.
61+
62+
Next and Previous here is linked to the group of links to be displayed in the pagination structure, and not to the next or previous page of records.
63+
6064
If you prefer a simpler output, you can use the ``simpleLinks()`` method, which only uses "Older" and "Newer" links,
6165
instead of the details pagination links::
6266

@@ -229,13 +233,13 @@ usefulness. It is easiest to demonstrate creating a new view by showing you the
229233
<ul class="pagination">
230234
<?php if ($pager->hasPrevious()) : ?>
231235
<li>
232-
<a href="<?= $pager->getFirst() ?>" aria-label="First">
233-
<span aria-hidden="true">First</span>
236+
<a href="<?= $pager->getFirst() ?>" aria-label="<?= lang('Pager.first') ?>">
237+
<span aria-hidden="true"><?= lang('Pager.first') ?></span>
234238
</a>
235239
</li>
236240
<li>
237-
<a href="<?= $pager->getPrevious() ?>" aria-label="Previous">
238-
<span aria-hidden="true">&laquo;</span>
241+
<a href="<?= $pager->getPrevious() ?>" aria-label="<?= lang('Pager.previous') ?>">
242+
<span aria-hidden="true"><?= lang('Pager.previous') ?></span>
239243
</a>
240244
</li>
241245
<?php endif ?>
@@ -250,13 +254,13 @@ usefulness. It is easiest to demonstrate creating a new view by showing you the
250254

251255
<?php if ($pager->hasNext()) : ?>
252256
<li>
253-
<a href="<?= $pager->getNext() ?>" aria-label="Previous">
254-
<span aria-hidden="true">&raquo;</span>
257+
<a href="<?= $pager->getNext() ?>" aria-label="<?= lang('Pager.next') ?>">
258+
<span aria-hidden="true"><?= lang('Pager.next') ?></span>
255259
</a>
256260
</li>
257261
<li>
258-
<a href="<?= $pager->getLast() ?>" aria-label="Last">
259-
<span aria-hidden="true">Last</span>
262+
<a href="<?= $pager->getLast() ?>" aria-label="<?= lang('Pager.last') ?>">
263+
<span aria-hidden="true"><?= lang('Pager.last') ?></span>
260264
</a>
261265
</li>
262266
<?php endif ?>
@@ -296,3 +300,57 @@ title, which is just the number, and a boolean that tells whether the link is th
296300
'uri' => 'http://example.com/foo?page=2',
297301
'title' => 1
298302
];
303+
304+
In the code presented for the standard pagination structure, the methods ``getPrevious()`` and ``getNext()`` are used to obtain the links to the previous and next pagination groups respectively.
305+
306+
If you want to use the pagination structure where prev and next will be links to the previous and next pages based on the current page, just replace the ``getPrevious()`` and ``getNext()`` methods with ``getPreviousPage()`` and ``getNextPage()``, and the methods ``hasPrevious()`` and ``hasNext()`` by ``hasPreviousPage()`` and ``hasNextPage()`` respectively.
307+
308+
See following an example with these changes::
309+
310+
<nav aria-label="<?= lang('Pager.pageNavigation') ?>">
311+
<ul class="pagination">
312+
<?php if ($pager->hasPreviousPage()) : ?>
313+
<li>
314+
<a href="<?= $pager->getFirst() ?>" aria-label="<?= lang('Pager.first') ?>">
315+
<span aria-hidden="true"><?= lang('Pager.first') ?></span>
316+
</a>
317+
</li>
318+
<li>
319+
<a href="<?= $pager->getPreviousPage() ?>" aria-label="<?= lang('Pager.previous') ?>">
320+
<span aria-hidden="true"><?= lang('Pager.previous') ?></span>
321+
</a>
322+
</li>
323+
<?php endif ?>
324+
325+
<?php foreach ($pager->links() as $link) : ?>
326+
<li <?= $link['active'] ? 'class="active"' : '' ?>>
327+
<a href="<?= $link['uri'] ?>">
328+
<?= $link['title'] ?>
329+
</a>
330+
</li>
331+
<?php endforeach ?>
332+
333+
<?php if ($pager->hasNextPage()) : ?>
334+
<li>
335+
<a href="<?= $pager->getNextPage() ?>" aria-label="<?= lang('Pager.next') ?>">
336+
<span aria-hidden="true"><?= lang('Pager.next') ?></span>
337+
</a>
338+
</li>
339+
<li>
340+
<a href="<?= $pager->getLast() ?>" aria-label="<?= lang('Pager.last') ?>">
341+
<span aria-hidden="true"><?= lang('Pager.last') ?></span>
342+
</a>
343+
</li>
344+
<?php endif ?>
345+
</ul>
346+
</nav>
347+
348+
**hasPreviousPage()** & **hasNextPage()**
349+
350+
This method returns a boolean true if there are links to a page before and after, respectively, the current page being displayed.
351+
352+
Their difference to ``hasPrevious()`` and ``hasNext()`` is that they are based on the current page while ``hasPrevious()`` and ``hasNext()`` are based on the set of links to be displayed before and after the current page based on the value passed in ``setSurroundCount``.
353+
354+
**getPreviousPage()** & **getNextPage()**
355+
356+
These methods return a URL for the previous and next pages in relation to the current page being displayed, unlike ``getPrevious()`` and ``getNext()`` that return the URL for the previous or next pages of results on either side of the numbered links. See the previous paragraph for a full explanation.

0 commit comments

Comments
 (0)