This commit is contained in:
boris
2024-12-01 18:15:35 +00:00
parent c650dbce01
commit 6430dc6904
3 changed files with 8 additions and 45 deletions

View File

@@ -40,39 +40,6 @@ class Paginator {
]);
}
public function setPageUri($page)
{
$uri = $_SERVER['REQUEST_URI'];
$uriComp = parse_url($uri);
$params = [];
// Parse existing query parameters
if (isset($uriComp['query'])) {
parse_str($uriComp['query'], $params);
} else {
$params = array();
}
// Avoid unnecessary redirection if the page is already correct
if (isset($params['page']) && (int)$params['page'] === $page) {
exit; // Do nothing if already on the correct page
}
// Update the 'page' parameter
$params['page'] = $page;
// Rebuild the query string
$newUri = http_build_query($params);
// Redirect to the updated URI
// Use the current path or root
return
[
'newUri' => $newUri,
'path' => $uriComp['path'] ?? '/'
];
}
public function getPage(int $pageNumber): array {
if ($pageNumber < 0 || $pageNumber >= $this->_totalPages) {