Skip to content

Commit

Permalink
Merge pull request #5602 from kenjis/fix-docs-pagination.rstv
Browse files Browse the repository at this point in the history
docs: improve pagination.rst
  • Loading branch information
kenjis committed Jan 21, 2022
2 parents 8081122 + ea76b26 commit a7e9207
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions user_guide_src/source/libraries/pagination.rst
Expand Up @@ -50,11 +50,11 @@ To provide a paginated list of users in your application, your controller's meth
}
}

In this example, we first create a new instance of our UserModel. Then we populate the data to send to the view.
In this example, we first create a new instance of our ``UserModel``. Then we populate the data to send to the view.
The first element is the results from the database, **users**, which is retrieved for the correct page, returning
10 users per page. The second item that must be sent to the view is the Pager instance itself. As a convenience,
the Model will hold on to the instance it used and store it in the public class variable, **$pager**. So, we grab
that and assign it to the $pager variable in the view.
the Model will hold on to the instance it used and store it in the public property, ``$pager``. So, we grab
that and assign it to the ``$pager`` variable in the view.

.. important:: It is important to understand that the Model::paginate() method uses the Model and QueryBuilder methods.
Therefore, trying to use ``$db->query()`` and Model::paginate() **will not work** because ``$db->query()`` executes
Expand Down Expand Up @@ -131,7 +131,7 @@ Setting Page Manually
=====================

If you need to specify which page of results to return you can specify the page as the 3rd argument. This can be
handy when you have a different manner than the default $_GET varibable to control which page to show.
handy when you have a different manner than the default ``$_GET`` varibable to control which page to show.

::

Expand All @@ -145,11 +145,11 @@ Specifying the URI Segment for Page

It is also possible to use a URI segment for the page number, instead of the page query parameter. Simply specify the
segment number to use as the fourth argument. URIs generated by the pager would then look
like *https://domain.tld/model/[pageNumber]* instead of *https://domain.tld/model?page=[pageNumber]*.
like **https://domain.tld/foo/bar/[pageNumber]** instead of **https://domain.tld/foo/bar?page=[pageNumber]**.

::

$users = $userModel->paginate(10, 'group1', null, 3);
$users = $userModel->paginate(10, 'group1', null, $segment);

Please note: ``$segment`` value cannot be greater than the number of URI segments plus 1.

Expand Down Expand Up @@ -185,22 +185,22 @@ If you in need to show many pagers on one page then additional parameter which w
$pager->setPath('path/for/my-group', 'my-group'); // Additionally you could define path for every group.
$pager->makeLinks($page, $perPage, $total, 'template_name', $segment, 'my-group');

Pagination library uses *page* query parameter for HTTP queries by default (if no group or *default* group name given) or *page_[groupName]* for custom group names.
Pagination library uses **page** query parameter for HTTP queries by default (if no group or ``default`` group name given) or ``page_[groupName]`` for custom group names.

Paginating with Only Expected Queries
=====================================

By default, all GET queries are shown in the pagination links.

For example, when accessing the URL *http://domain.tld?search=foo&order=asc&hello=i+am+here&page=2*, the page 3 link can be generated, along with the other links, as follows::
For example, when accessing the URL **https://domain.tld?search=foo&order=asc&hello=i+am+here&page=2**, the page 3 link can be generated, along with the other links, as follows::

echo $pager->links();
// Page 3 link: http://domain.tld?search=foo&order=asc&hello=i+am+here&page=3
// Page 3 link: https://domain.tld?search=foo&order=asc&hello=i+am+here&page=3

The ``only()`` method allows you to limit this just to queries already expected::

echo $pager->only(['search', 'order'])->links();
// Page 3 link: http://domain.tld?search=foo&order=asc&page=3
// Page 3 link: https://domain.tld?search=foo&order=asc&page=3

The *page* query is enabled by default. And ``only()`` acts in all pagination links.

Expand All @@ -220,7 +220,7 @@ that is used by editing **app/Config/Pager.php**::
];

This setting stores the alias and :doc:`namespaced view paths </outgoing/views>` for the view that
should be used. The *default_full* and *default_simple* views are used for the ``links()`` and ``simpleLinks()``
should be used. The ``default_full`` and ``default_simple`` views are used for the ``links()`` and ``simpleLinks()``
methods, respectively. To change the way those are displayed application-wide, you could assign a new view here.

For example, say you create a new view file that works with the Foundation CSS framework, and
Expand Down Expand Up @@ -258,7 +258,7 @@ Creating the View

When you create a new view, you only need to create the code that is needed for creating the pagination links themselves.
You should not create unnecessary wrapping divs since it might be used in multiple places and you only limit their
usefulness. It is easiest to demonstrate creating a new view by showing you the existing default_full template::
usefulness. It is easiest to demonstrate creating a new view by showing you the existing ``default_full`` template::

<?php $pager->setSurroundCount(2) ?>

Expand Down Expand Up @@ -308,7 +308,7 @@ the current page link. The only parameter that it accepts is the number of links
**hasPrevious()** & **hasNext()**

These methods return a boolean true if there are more links that can be displayed on either side of the current page,
based on the value passed to ``setSurroundCount``. For example, let's say we have 20 pages of data. The current
based on the value passed to ``setSurroundCount()``. For example, let's say we have 20 pages of data. The current
page is page 3. If the surrounding count is 2, then the following links would show up in the list: 1, 2, 3, 4, and 5.
Since the first link displayed is page one, ``hasPrevious()`` would return **false** since there is no page zero. However,
``hasNext()`` would return **true** since there are 15 additional pages of results after page five.
Expand All @@ -330,7 +330,7 @@ title, which is just the number, and a boolean that tells whether the link is th

$link = [
'active' => false,
'uri' => 'http://example.com/foo?page=2',
'uri' => 'https://example.com/foo?page=2',
'title' => 1,
];

Expand Down Expand Up @@ -382,7 +382,7 @@ See following an example with these changes::

This method returns a boolean true if there are links to a page before and after, respectively, the current page being displayed.

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``.
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()``.

**getPreviousPage()** & **getNextPage()**

Expand Down

0 comments on commit a7e9207

Please sign in to comment.