The offset value must be greater than or equal to zero – CodeIgniter 4 Pagination library
0 reputation · 29 Feb 2020, 00:54 UTC
The goal is to use CodeIgniter 4’s Pagination library to display large datasets without encountering the validation error "The offset value must be greater than or equal to zero." The library computes the offset as ($page - 1) * $perPage and passes it directly to the Query Builder’s limit method, which throws the error when the offset is negative. There is no automatic guard against negative offsets in the pagination component, leaving it to developers to ensure that page numbers and per_page settings produce only non‑negative values.
This raises uncertainty about whether the framework should clamp negative offsets to zero, validate page numbers internally, or rely on developer‑side checks. The lack of clear guidance in the documentation makes the behavior ambiguous across different deployment scenarios.
- Should the Pagination library automatically adjust negative offsets to zero before calling the Query Builder?
- Is it acceptable for developers to validate the current page number (ensuring it is ≥ 1) before invoking pagination, or should the framework enforce this?
- Does the Query Builder’s limit method need to treat a negative offset as zero instead of throwing an error?