Skip to content

[Patch] Optimization CreateUrl() #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
PHP Paginator with Pager Widget (pure PHP, CI, Yii, Laravel support)

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

Features
Expand Down Expand Up @@ -236,18 +235,29 @@ echo Pagination::widget([

#### Customized View

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

```php
use yidas\widgets\Pagination;

echo Pagination::widget([
echo \yidas\widgets\Pagination::widget([
'pagination' => $pagination,
'view' => $appPagerViewPath,
'view' => 'simple',
]);
```

> You could also choose library's template view: `bootstrap`, `simple`
|Template |Description|
|:--------|:----------|
|bootstrap|Default view, supports for Bootstrap 3 and 4|
|simple |Simple `<div>` with `<a>` tags for pure HTML/CSS style|


You can also use your customized view for Pagination widget:

```php
echo \yidas\widgets\Pagination::widget([
'pagination' => $pagination,
'view' => __DIR__ . '/../widgets/pagination_view.php',
]);
```

#### Inheritance

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

---

Expand Down
9 changes: 6 additions & 3 deletions src/data/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,15 @@ public function createUrl($page, $prePage=null)
{
$requestUri = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
// Add or reset page parameter
$_GET[$this->pageParam] = (int) $page;
$isPage = (int) $page;
$ppParam = '';
if ($this->perPageParam) {
$_GET[$this->perPageParam] = ($prePage) ? $prePage : $this->perPage;
$isPerPage = ($prePage) ? $prePage : $this->perPage;
$ppParam = "&{$this->perPageParam}={$isPerPage}";
}

// Build URL
$url = "//{$_SERVER['HTTP_HOST']}{$requestUri}?" . http_build_query($_GET);
$url = "//{$_SERVER['HTTP_HOST']}{$requestUri}?" . http_build_query($_GET) . "&{$this->pageParam}={$isPage}{$ppParam}";

return $url;
}
Expand Down