From 23a875ecc2215c9a0d2b51bf6d4d1e6087060caa Mon Sep 17 00:00:00 2001 From: Nick Tsai Date: Mon, 29 May 2023 10:42:01 +0800 Subject: [PATCH] Enable ->params --- src/data/Pagination.php | 6 ++++-- test/test.php | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/data/Pagination.php b/src/data/Pagination.php index 4debe7a..0978241 100644 --- a/src/data/Pagination.php +++ b/src/data/Pagination.php @@ -74,7 +74,7 @@ class Pagination * * @var array */ - public $params; + public $params = []; /** * Total number of items @@ -183,8 +183,10 @@ public function createUrl($page, $perPage=null) if ($this->perPageParam) { $params[$this->perPageParam] = ($perPage) ? $perPage : $this->perPage; } + // Verify $this->params + $this->params = is_array($this->params) ? $this->params : []; // Build URL - $url = "//{$_SERVER['HTTP_HOST']}{$requestUri}?" . http_build_query(array_merge($_GET, $params)); + $url = "//{$_SERVER['HTTP_HOST']}{$requestUri}?" . http_build_query(array_merge($_GET, $this->params, $params)); return $url; } diff --git a/test/test.php b/test/test.php index 6100052..160108c 100644 --- a/test/test.php +++ b/test/test.php @@ -7,6 +7,9 @@ $pagination = new \yidas\data\Pagination([ 'totalCount' => $count, + 'params' => [ + 'key' => 'value', + ], ]); ?>