From c307fec459eb6b70a0bab2dd77b1c82c5c8a2e28 Mon Sep 17 00:00:00 2001 From: TysiacSzescset Date: Thu, 19 Mar 2020 17:40:22 +0100 Subject: [PATCH 1/2] Pager makeLinks $group param fix --- system/Pager/Pager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Pager/Pager.php b/system/Pager/Pager.php index 8aecd5f26e8c..f3b27bec1797 100644 --- a/system/Pager/Pager.php +++ b/system/Pager/Pager.php @@ -154,7 +154,7 @@ public function simpleLinks(string $group = 'default', string $template = 'defau * @param string|null $group optional group (i.e. if we'd like to define custom path) * @return string */ - public function makeLinks(int $page, int $perPage, int $total, string $template = 'default_full', int $segment = 0, ?string $group = null): string + public function makeLinks(int $page, int $perPage, int $total, string $template = 'default_full', int $segment = 0, ?string $group = 'default'): string { $name = time(); From f0d0628722b0706f7df5ddc749751a1d99bbf31e Mon Sep 17 00:00:00 2001 From: TysiacSzescset Date: Mon, 23 Mar 2020 18:48:50 +0100 Subject: [PATCH 2/2] Pager fix, Pager test added, Guide update --- system/Pager/Pager.php | 8 ++++---- tests/system/Pager/PagerTest.php | 12 ++++++++++++ user_guide_src/source/libraries/pagination.rst | 4 +++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/system/Pager/Pager.php b/system/Pager/Pager.php index f3b27bec1797..403fcbd62962 100644 --- a/system/Pager/Pager.php +++ b/system/Pager/Pager.php @@ -151,16 +151,16 @@ public function simpleLinks(string $group = 'default', string $template = 'defau * @param string $template The output template alias to render. * @param integer $segment (if page number is provided by URI segment) * - * @param string|null $group optional group (i.e. if we'd like to define custom path) + * @param string $group optional group (i.e. if we'd like to define custom path) * @return string */ public function makeLinks(int $page, int $perPage, int $total, string $template = 'default_full', int $segment = 0, ?string $group = 'default'): string { - $name = time(); + $group = $group === '' ? 'default' : $group; - $this->store($group ?? $name, $page, $perPage, $total, $segment); + $this->store($group, $page, $perPage, $total, $segment); - return $this->displayLinks($group ?? $name, $template); + return $this->displayLinks($group, $template); } //-------------------------------------------------------------------- diff --git a/tests/system/Pager/PagerTest.php b/tests/system/Pager/PagerTest.php index 287f5dd410aa..b0b8919657a7 100644 --- a/tests/system/Pager/PagerTest.php +++ b/tests/system/Pager/PagerTest.php @@ -343,6 +343,18 @@ public function testMakeLinks() $this->assertStringContainsString( 'pager->makeLinks(4, 10, 50, 'default_head') ); + $this->assertStringContainsString( + '?page=1', $this->pager->makeLinks(1, 10, 1, 'default_full', 0) + ); + $this->assertStringContainsString( + '?page=1', $this->pager->makeLinks(1, 10, 1, 'default_full', 0, '') + ); + $this->assertStringContainsString( + '?page=1', $this->pager->makeLinks(1, 10, 1, 'default_full', 0, 'default') + ); + $this->assertStringContainsString( + '?page_custom=1', $this->pager->makeLinks(1, 10, 1, 'default_full', 0, 'custom') + ); } public function testHeadLinks() diff --git a/user_guide_src/source/libraries/pagination.rst b/user_guide_src/source/libraries/pagination.rst index 7569b1e11198..50acae3b3e3f 100644 --- a/user_guide_src/source/libraries/pagination.rst +++ b/user_guide_src/source/libraries/pagination.rst @@ -116,7 +116,9 @@ If you in need to show many pagers on one page then additional parameter which w $pager = service('pager'); $pager->setPath('path/for/my-group', 'my-group'); // Additionally you could define path for every group. - $pager->makeLinks($page, $perPage, $total, 'template_name', $segment, 'my-group'); + $pager->makeLinks($page, $perPage, $total, 'template_name', $segment, 'my-group'); + +Pagination library uses *page* query parameter for HTTP queries by default (if no group or *default* group name given) or *page_[groupName]* for custom group names. Paginating with Only Expected Queries =====================================