From d6c25bd0e305a5860f8f6cb6f7a17971b35d2932 Mon Sep 17 00:00:00 2001 From: euromark Date: Mon, 24 Jun 2013 00:03:08 +0200 Subject: [PATCH] add convenience method param() for PaginatorHelper --- .../Case/View/Helper/PaginatorHelperTest.php | 26 ++++++++++++++++++- lib/Cake/View/Helper/PaginatorHelper.php | 16 ++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php b/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php index a2da52bde..c6a346d18 100644 --- a/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php @@ -2143,7 +2143,31 @@ class PaginatorHelperTest extends CakeTestCase { } /** - * test Last method + * test params() method + * + * @return void + */ + public function testParams() { + $result = $this->Paginator->params(); + $this->assertArrayHasKey('page', $result); + $this->assertArrayHasKey('pageCount', $result); + } + +/** + * test param() method + * + * @return void + */ + public function testParam() { + $result = $this->Paginator->param('count'); + $this->assertIdentical(62, $result); + + $result = $this->Paginator->param('imaginary'); + $this->assertNull($result); + } + +/** + * test last() method * * @return void */ diff --git a/lib/Cake/View/Helper/PaginatorHelper.php b/lib/Cake/View/Helper/PaginatorHelper.php index 09af0d16c..78add68ac 100644 --- a/lib/Cake/View/Helper/PaginatorHelper.php +++ b/lib/Cake/View/Helper/PaginatorHelper.php @@ -133,6 +133,22 @@ class PaginatorHelper extends AppHelper { return $this->request->params['paging'][$model]; } +/** + * Convenience access to any of the paginator params. + * + * @param string $key Key of the paginator params array to retreive. + * @param string $model Optional model name. Uses the default if none is specified. + * @return mixed Content of the requested param. + * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::params + */ + public function param($key, $model = null) { + $params = $this->params($model); + if (!isset($params[$key])) { + return null; + } + return $params[$key]; + } + /** * Sets default options for all pagination links *