Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions system/Pager/Pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = null): 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);
}

//--------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions tests/system/Pager/PagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,18 @@ public function testMakeLinks()
$this->assertStringContainsString(
'<link rel="canonical"', $this->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()
Expand Down
4 changes: 3 additions & 1 deletion user_guide_src/source/libraries/pagination.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=====================================
Expand Down