From a3cfafc761351e18705d5a394f0b8259a11b337f Mon Sep 17 00:00:00 2001 From: Qiang Xue <qiang.xue@gmail.com> Date: Wed, 17 Sep 2014 11:14:05 -0400 Subject: [PATCH] Fixes #5058: Added `$pageSize` parameter to `Pagination::createUrl()` to allow creating URLs with arbitrary page sizes --- framework/CHANGELOG.md | 1 + framework/data/Pagination.php | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index c3269b5..b36eddc 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -210,6 +210,7 @@ Yii Framework 2 Change Log - Enh #4691: Encoding on `ActiveForm` and `ActiveField` validation errors is now configurable (Alex-Code) - Enh #4740: Added `yii\web\Session::addFlash()` (restyler) - Enh #4897: Added `yii\helpers\FileHelper::mimeMagicFile` (qiangxue) +- Enh #5058: Added `$pageSize` parameter to `Pagination::createUrl()` to allow creating URLs with arbitrary page sizes (cdcchen, qiangxue) - Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue) - Enh: Supported adding a new response formatter without the need to reconfigure existing formatters (qiangxue) - Enh: Added `yii\web\UrlManager::addRules()` to simplify adding new URL rules (qiangxue) diff --git a/framework/data/Pagination.php b/framework/data/Pagination.php index 78fdd5a..a783832 100644 --- a/framework/data/Pagination.php +++ b/framework/data/Pagination.php @@ -246,13 +246,16 @@ class Pagination extends Object implements Linkable * Creates the URL suitable for pagination with the specified page number. * This method is mainly called by pagers when creating URLs used to perform pagination. * @param integer $page the zero-based page number that the URL should point to. + * @param integer $pageSize the number of items on each page. If 0, the value of [[pageSize]] will be used. * @param boolean $absolute whether to create an absolute URL. Defaults to `false`. * @return string the created URL * @see params * @see forcePageParam */ - public function createUrl($page, $absolute = false) + public function createUrl($page, $pageSize = 0, $absolute = false) { + $page = (int) $page; + $pageSize = (int) $pageSize; if (($params = $this->params) === null) { $request = Yii::$app->getRequest(); $params = $request instanceof Request ? $request->getQueryParams() : []; @@ -262,7 +265,9 @@ class Pagination extends Object implements Linkable } else { unset($params[$this->pageParam]); } - $pageSize = $this->getPageSize(); + if ($pageSize <= 0) { + $pageSize = $this->getPageSize(); + } if ($pageSize != $this->defaultPageSize) { $params[$this->pageSizeParam] = $pageSize; } else { -- libgit2 0.27.1