Skip to content

Commit cc01bd4

Browse files
committed
Optimize createUrl() to remove the influence of Query string
1 parent b340639 commit cc01bd4

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
PHP Paginator with Pager Widget (pure PHP, CI, Yii, Laravel support)
55

66
[![Latest Stable Version](https://poser.pugx.org/yidas/pagination/v/stable?format=flat-square)](https://packagist.org/packages/yidas/pagination)
7-
[![Latest Unstable Version](https://poser.pugx.org/yidas/pagination/v/unstable?format=flat-square)](https://packagist.org/packages/yidas/pagination)
87
[![License](https://poser.pugx.org/yidas/pagination/license?format=flat-square)](https://packagist.org/packages/yidas/pagination)
98

109
Features
@@ -236,18 +235,29 @@ echo Pagination::widget([
236235
237236
#### Customized View
238237

239-
The default widget view is for Bootstrap(`bootstrap`), you could customized your pagination view then set into Pagination Widget.
238+
The default widget view is for Bootstrap(`bootstrap`), you could choose a template view for your Pagination Widget:
240239

241240
```php
242-
use yidas\widgets\Pagination;
243-
244-
echo Pagination::widget([
241+
echo \yidas\widgets\Pagination::widget([
245242
'pagination' => $pagination,
246-
'view' => $appPagerViewPath,
243+
'view' => 'simple',
247244
]);
248245
```
249246

250-
> You could also choose library's template view: `bootstrap`, `simple`
247+
|Template |Description|
248+
|:--------|:----------|
249+
|bootstrap|Default view, supports for Bootstrap 3 and 4|
250+
|simple |Simple `<div>` with `<a>` tags for pure HTML/CSS style|
251+
252+
253+
You can also use your customized view for Pagination widget:
254+
255+
```php
256+
echo \yidas\widgets\Pagination::widget([
257+
'pagination' => $pagination,
258+
'view' => __DIR__ . '/../widgets/pagination_view.php',
259+
]);
260+
```
251261

252262
#### Inheritance
253263

@@ -426,7 +436,7 @@ API DOCUMENTATION
426436
|$pageCssClass|string |The CSS class for the each page button, default value is `page-item`|
427437
|$ulCssClass |string |The CSS class for the ul element of pagination. For example, 'pagination-sm' for Bootstrap small size.|
428438
|$linkAttributes|array |HTML attributes for the link in a pager container tag, default value is ['class' => 'page-link']|
429-
|$view |string |The view name or absolute file path that can be used to render view. (Template: `bootstrap`, `simple`)|
439+
|$view |string |The view name or absolute file path that can be used to render view. ([Template view choices](#customized-view))|
430440

431441
---
432442

src/data/Pagination.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Pagination
99
*
1010
* @author Nick Tsai <myintaer@gmail.com>
11-
* @version 1.0.5
11+
* @version 1.0.7
1212
*/
1313
class Pagination
1414
{
@@ -175,16 +175,16 @@ public function setPerPage($perPage)
175175
* @param integer $perPage
176176
* @return string
177177
*/
178-
public function createUrl($page, $prePage=null)
178+
public function createUrl($page, $perPage=null)
179179
{
180180
$requestUri = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
181181
// Add or reset page parameter
182-
$_GET[$this->pageParam] = (int) $page;
182+
$params[$this->pageParam] = (int) $page;
183183
if ($this->perPageParam) {
184-
$_GET[$this->perPageParam] = ($prePage) ? $prePage : $this->perPage;
184+
$params[$this->perPageParam] = ($perPage) ? $perPage : $this->perPage;
185185
}
186186
// Build URL
187-
$url = "//{$_SERVER['HTTP_HOST']}{$requestUri}?" . http_build_query($_GET);
187+
$url = "//{$_SERVER['HTTP_HOST']}{$requestUri}?" . http_build_query(array_merge($_GET, $params));
188188

189189
return $url;
190190
}

0 commit comments

Comments
 (0)