Open jorqensen opened 1 month ago
@jorqensen ,
The currentPage
variable is used to track which page the paginator is currently on. When you start and haven't made any requests, the current page is 0 (or, startPage - 1
, if you've set the start page). Once you request page 1, then the currentPage
will advance to 1.
The applyPagination()
method is called before requests to update the request to get the next page. Since you're trying to get the next page, and not the current page, you want to update the request with $this->currentPage + 1
.
If you look at the applyPagination()
method on the parent PagedPaginator
class, you'll see it still uses the deprecated page
property (which is equal to $this->currentPage + 1
).
Since this property is deprecated, I tend to use $this->currentPage + 1
in my own custom paginators. Also, the $this->currentPage + 1
logic is used multiple times inside the parent Paginator
class.
Hey @jorqensen
As Patrick kindly mentioned, the page
property does start at 1, but that meant that by the time it ran applyPagination
, that value was actually 2, so I deprecated it and introduced currentPage
which is the "correct" value. Patrick's suggestion above should be suitable to get pagination working.
I stumbled across something rather annoying with the pagination plugin, perhaps I am misunderstanding something. Clarification would be appreciated.
I'm working with an API that uses
limit
andpage
for pagination, so I've set my pagination up as such:However, this means that my pagination will start at page 0 as
currentPage
is set to 0. Applying->setStartPage()
on the paginator doesn't do anything, neither does setting thecurrentPage
property on my pagination class to 1.Moving to the deprecated
page
property will make everything work as expected:What's the idea for
currentPage
not starting at 1? Or how do you actually properly set the starting page to 1, without making use of the deprecated/internal property?