Skip to content

Commit ee1718f

Browse files
authored
Merge branch 'codeigniter4:develop' into add-curlrequest-curlopt_ssl_verifyhost
2 parents 7ab7cf5 + 93e9c6b commit ee1718f

File tree

2 files changed

+55
-25
lines changed

2 files changed

+55
-25
lines changed

system/Pager/PagerRenderer.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
class PagerRenderer
2626
{
2727
/**
28-
* First page number.
28+
* First page number in the set of links to be displayed.
2929
*
3030
* @var int
3131
*/
3232
protected $first;
3333

3434
/**
35-
* Last page number.
35+
* Last page number in the set of links to be displayed.
3636
*
3737
* @var int
3838
*/
@@ -85,8 +85,11 @@ class PagerRenderer
8585
*/
8686
public function __construct(array $details)
8787
{
88-
$this->first = 1;
89-
$this->last = $details['pageCount'];
88+
// `first` and `last` will be updated by `setSurroundCount()`.
89+
// You must call `setSurroundCount()` after instantiation.
90+
$this->first = 1;
91+
$this->last = $details['pageCount'];
92+
9093
$this->current = $details['currentPage'];
9194
$this->total = $details['total'];
9295
$this->uri = $details['uri'];
@@ -122,8 +125,6 @@ public function hasPrevious(): bool
122125
* page before the current page, but is the page just before the
123126
* "first" page.
124127
*
125-
* You MUST call hasPrevious() first, or this value may be invalid.
126-
*
127128
* @return string|null
128129
*/
129130
public function getPrevious()
@@ -162,8 +163,6 @@ public function hasNext(): bool
162163
* page after the current page, but is the page that follows the
163164
* "last" page.
164165
*
165-
* You MUST call hasNext() first, or this value may be invalid.
166-
*
167166
* @return string|null
168167
*/
169168
public function getNext()
@@ -260,6 +259,8 @@ public function getCurrent(): string
260259
* is represented by another array containing of the URI the link
261260
* should go to, the title (number) of the link, and a boolean
262261
* value representing whether this link is active or not.
262+
*
263+
* @return list<array{uri:string, title:int, active:bool}>
263264
*/
264265
public function links(): array
265266
{
@@ -381,7 +382,7 @@ public function getNextPage()
381382
}
382383

383384
/**
384-
* Returns the page number of the first page.
385+
* Returns the page number of the first page in the set of links to be displayed.
385386
*/
386387
public function getFirstPageNumber(): int
387388
{
@@ -397,7 +398,7 @@ public function getCurrentPageNumber(): int
397398
}
398399

399400
/**
400-
* Returns the page number of the last page.
401+
* Returns the page number of the last page in the set of links to be displayed.
401402
*/
402403
public function getLastPageNumber(): int
403404
{

user_guide_src/source/libraries/pagination.rst

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -227,32 +227,39 @@ setSurroundCount()
227227
In the first line, the ``setSurroundCount()`` method specifies than we want to show two links to either side of
228228
the current page link. The only parameter that it accepts is the number of links to show.
229229

230+
.. note:: You must call this method first to generate correct pagination links.
231+
230232
hasPrevious() & hasNext()
231233
-------------------------
232234

233-
These methods return a boolean true if there are more links that can be displayed on either side of the current page,
234-
based on the value passed to ``setSurroundCount()``. For example, let's say we have 20 pages of data. The current
235-
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.
236-
Since the first link displayed is page one, ``hasPrevious()`` would return **false** since there is no page zero. However,
237-
``hasNext()`` would return **true** since there are 15 additional pages of results after page five.
235+
These methods return a boolean ``true`` if there are more links that can be displayed on either side of the current page,
236+
based on the value passed to `setSurroundCount()`_.
237+
238+
For example, let's say we have 20 pages of data. The current
239+
page is page 3. If the surrounding count is 2, then the following links would show up like this::
240+
241+
1 | 2 | 3 | 4 | 5
242+
243+
Since the first link displayed is page one, ``hasPrevious()`` would return ``false`` since there is no page zero. However,
244+
``hasNext()`` would return ``true`` since there are 15 additional pages of results after page five.
238245

239246
getPrevious() & getNext()
240247
-------------------------
241248

242-
These methods return the URL for the previous or next pages of results on either side of the numbered links.
249+
These methods return the **URL** for the previous or next pages of results on either side of the numbered links.
243250

244251
For example, you have the current page set at 5 and you want to have the links before and after (the surroundCount) to be 2 each, that will give you something like this::
245252

246253
3 | 4 | 5 | 6 | 7
247254

248255
``getPrevious()`` returns the URL for page 2. ``getNext()`` returns the URL for page 8.
249256

250-
If you want to get page 4 and page 6, use ``getPreviousPage()`` and ``getNextPage()`` instead.
257+
If you want to get page 4 and page 6, use `getPreviousPage() & getNextPage()`_ instead.
251258

252259
getFirst() & getLast()
253260
----------------------
254261

255-
Much like ``getPrevious()`` and ``getNext()``, these methods return links to the first and last pages in the
262+
Much like `getPrevious() & getNext()`_, these methods return the **URL** to the first and last pages in the
256263
result set.
257264

258265
links()
@@ -263,9 +270,9 @@ title, which is just the number, and a boolean that tells whether the link is th
263270

264271
.. literalinclude:: pagination/013.php
265272

266-
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.
273+
In the code presented for the standard pagination structure, the methods `getPrevious() & getNext()`_ are used to obtain the links to the previous and next pagination groups respectively.
267274

268-
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.
275+
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() & getNext()`_ methods with `getPreviousPage() & getNextPage()`_, and the methods `hasPrevious() & hasNext()`_ by `hasPreviousPage() & hasNextPage()`_ respectively.
269276

270277
See following an example with these changes:
271278

@@ -274,21 +281,35 @@ See following an example with these changes:
274281
hasPreviousPage() & hasNextPage()
275282
---------------------------------
276283

277-
This method returns a boolean true if there are links to a page before and after, respectively, the current page being displayed.
284+
This method returns a boolean ``true`` if there are links to a page before and after, respectively, the current page being displayed.
285+
286+
For example, let's say we have 20 pages of data. The current
287+
page is page 3. If the surrounding count is 2, then the following links would show up like this::
288+
289+
1 | 2 | 3 | 4 | 5
290+
291+
``hasPreviousPage()`` would return ``true`` since there is page 2. And,
292+
``hasNextPage()`` would return ``true`` since there is page 4.
278293

279-
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()``.
294+
.. note:: The difference to `hasPrevious() & hasNext()`_ is that they are based
295+
on the current page while `hasPrevious() & hasNext()`_ are based on the set
296+
of links to be displayed before and after the current page based on the value
297+
passed in `setSurroundCount()`_.
280298

281299
getPreviousPage() & getNextPage()
282300
---------------------------------
283301

284-
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.
302+
These methods return a **URL** for the previous and next pages in relation to the current page being displayed.
285303

286304
For example, you have the current page set at 5 and you want to have the links before and after (the surroundCount) to be 2 each, that will give you something like this::
287305

288306
3 | 4 | 5 | 6 | 7
289307

290308
``getPreviousPage()`` returns the URL for page 4. ``getNextPage()`` returns the URL for page 6.
291309

310+
.. note:: `getPrevious() & getNext()`_ returns the URL for the previous or next
311+
pages of results on either side of the numbered links.
312+
292313
If you want page numbers instead of URLs, you can use the following methods:
293314

294315
getPreviousPageNumber() & getNextPageNumber()
@@ -299,8 +320,16 @@ These methods return the page number for the previous or next pages in relation
299320
getFirstPageNumber() & getLastPageNumber()
300321
------------------------------------------
301322

302-
These methods return page numbers to the first and last pages in the
303-
result set.
323+
These methods return the page numbers of the first and last pages in the set of
324+
links to be displayed. For example, if the set of links to be displayed is something like this::
325+
326+
3 | 4 | 5 | 6 | 7
327+
328+
``getFirstPageNumber()`` will return 3 while ``getLastPageNumber()`` will return 7.
329+
330+
.. note:: To obtain the page numbers of the first and last pages in the entire
331+
result set, you can use the following approach: The first page number is always 1, and `getPageCount()`_ can be used to
332+
retrieve the last page number.
304333

305334
getCurrentPageNumber()
306335
----------------------

0 commit comments

Comments
 (0)