PageIndex: rewrite getLink to be way less messy
This commit is contained in:
parent
d8c3e76df6
commit
54ead63ac4
@ -155,24 +155,21 @@ class PageIndex
|
||||
|
||||
public function getLink($start = null, $order = null, $dir = null)
|
||||
{
|
||||
$url = $this->base_url;
|
||||
$amp = strpos($this->base_url, '?') ? '&' : '?';
|
||||
echo $start, "\n";
|
||||
$page = !is_string($start) ? ($start / $this->items_per_page) + 1 : $start;
|
||||
$url = $this->base_url . str_replace('%PAGE%', $page, $this->page_slug);
|
||||
|
||||
if (!empty($start))
|
||||
{
|
||||
$page = $start !== '%d' ? ($start / $this->items_per_page) + 1 : $start;
|
||||
$url .= strtr($this->page_slug, ['%PAGE%' => $page, '%AMP%' => $amp]);
|
||||
$amp = '&';
|
||||
}
|
||||
$urlParams = [];
|
||||
if (!empty($order))
|
||||
{
|
||||
$url .= $amp . 'order=' . $order;
|
||||
$amp = '&';
|
||||
}
|
||||
$urlParams['order'] = $order;
|
||||
if (!empty($dir))
|
||||
$urlParams['dir'] = $dir;
|
||||
|
||||
if (!empty($urlParams))
|
||||
{
|
||||
$url .= $amp . 'dir=' . $dir;
|
||||
$amp = '&';
|
||||
$queryString = (strpos($uri, '?') !== false ? '&' : '?');
|
||||
$queryString .= http_build_query($urlParams);
|
||||
$url .= $queryString;
|
||||
}
|
||||
|
||||
return $url;
|
||||
|
Loading…
Reference in New Issue
Block a user