Skip to content

Commit f0d0628

Browse files
Pager fix, Pager test added, Guide update
1 parent c307fec commit f0d0628

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

system/Pager/Pager.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,16 @@ public function simpleLinks(string $group = 'default', string $template = 'defau
151151
* @param string $template The output template alias to render.
152152
* @param integer $segment (if page number is provided by URI segment)
153153
*
154-
* @param string|null $group optional group (i.e. if we'd like to define custom path)
154+
* @param string $group optional group (i.e. if we'd like to define custom path)
155155
* @return string
156156
*/
157157
public function makeLinks(int $page, int $perPage, int $total, string $template = 'default_full', int $segment = 0, ?string $group = 'default'): string
158158
{
159-
$name = time();
159+
$group = $group === '' ? 'default' : $group;
160160

161-
$this->store($group ?? $name, $page, $perPage, $total, $segment);
161+
$this->store($group, $page, $perPage, $total, $segment);
162162

163-
return $this->displayLinks($group ?? $name, $template);
163+
return $this->displayLinks($group, $template);
164164
}
165165

166166
//--------------------------------------------------------------------

tests/system/Pager/PagerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,18 @@ public function testMakeLinks()
343343
$this->assertStringContainsString(
344344
'<link rel="canonical"', $this->pager->makeLinks(4, 10, 50, 'default_head')
345345
);
346+
$this->assertStringContainsString(
347+
'?page=1', $this->pager->makeLinks(1, 10, 1, 'default_full', 0)
348+
);
349+
$this->assertStringContainsString(
350+
'?page=1', $this->pager->makeLinks(1, 10, 1, 'default_full', 0, '')
351+
);
352+
$this->assertStringContainsString(
353+
'?page=1', $this->pager->makeLinks(1, 10, 1, 'default_full', 0, 'default')
354+
);
355+
$this->assertStringContainsString(
356+
'?page_custom=1', $this->pager->makeLinks(1, 10, 1, 'default_full', 0, 'custom')
357+
);
346358
}
347359

348360
public function testHeadLinks()

user_guide_src/source/libraries/pagination.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ If you in need to show many pagers on one page then additional parameter which w
116116

117117
$pager = service('pager');
118118
$pager->setPath('path/for/my-group', 'my-group'); // Additionally you could define path for every group.
119-
$pager->makeLinks($page, $perPage, $total, 'template_name', $segment, 'my-group');
119+
$pager->makeLinks($page, $perPage, $total, 'template_name', $segment, 'my-group');
120+
121+
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.
120122

121123
Paginating with Only Expected Queries
122124
=====================================

0 commit comments

Comments
 (0)