diff --git a/Cake/Test/TestCase/View/Helper/PaginatorHelperTest.php b/Cake/Test/TestCase/View/Helper/PaginatorHelperTest.php
index 86ca5497186..d1ff9760832 100644
--- a/Cake/Test/TestCase/View/Helper/PaginatorHelperTest.php
+++ b/Cake/Test/TestCase/View/Helper/PaginatorHelperTest.php
@@ -1400,6 +1400,39 @@ public function testNumbersRouting() {
$this->assertTags($result, $expected);
}
+/**
+ * Test that numbers() works with the non default model.
+ *
+ * @return void
+ */
+ public function testNumbersNonDefaultModel() {
+ $this->Paginator->request->params['paging'] = array(
+ 'Client' => array(
+ 'page' => 1,
+ 'current' => 3,
+ 'count' => 13,
+ 'prevPage' => false,
+ 'nextPage' => true,
+ 'pageCount' => 5,
+ ),
+ 'Server' => array(
+ 'page' => 5,
+ 'current' => 1,
+ 'count' => 5,
+ 'prevPage' => true,
+ 'nextPage' => false,
+ 'pageCount' => 5,
+ )
+ );
+ $result = $this->Paginator->numbers(['model' => 'Server']);
+ $this->assertContains('
5', $result);
+ $this->assertNotContains('1', $result);
+
+ $result = $this->Paginator->numbers(['model' => 'Client']);
+ $this->assertContains('1', $result);
+ $this->assertNotContains('5', $result);
+ }
+
/**
* test first() and last() with tag options
*
@@ -1443,6 +1476,37 @@ public function testLastNoOutput() {
$this->assertEquals($expected, $result);
}
+/**
+ * test first() with a the model parameter.
+ *
+ * @return void
+ */
+ public function testFirstNonDefaultModel() {
+ $this->Paginator->request->params['paging']['Article']['page'] = 1;
+ $this->Paginator->request->params['paging']['Client'] = array(
+ 'page' => 3,
+ 'current' => 3,
+ 'count' => 13,
+ 'prevPage' => false,
+ 'nextPage' => true,
+ 'pageCount' => 5,
+ );
+
+
+ $result = $this->Paginator->first('first', ['model' => 'Article:']);
+ $this->assertEquals('', $result);
+
+ $result = $this->Paginator->first('first', ['model' => 'Client']);
+ $expected = array(
+ 'li' => array('class' => 'first'),
+ 'a' => array('href' => '/index', 'rel' => 'first'),
+ 'first',
+ '/a',
+ '/li'
+ );
+ $this->assertTags($result, $expected);
+ }
+
/**
* test first() on the first page.
*
@@ -1632,6 +1696,36 @@ public function testLastOptions() {
$this->assertTags($result, $expected);
}
+/**
+ * test last() with a the model parameter.
+ *
+ * @return void
+ */
+ public function testLastNonDefaultModel() {
+ $this->Paginator->request->params['paging']['Article']['page'] = 7;
+ $this->Paginator->request->params['paging']['Client'] = array(
+ 'page' => 3,
+ 'current' => 3,
+ 'count' => 13,
+ 'prevPage' => false,
+ 'nextPage' => true,
+ 'pageCount' => 5,
+ );
+
+ $result = $this->Paginator->last('last', ['model' => 'Article:']);
+ $this->assertEquals('', $result);
+
+ $result = $this->Paginator->last('last', ['model' => 'Client']);
+ $expected = array(
+ 'li' => array('class' => 'last'),
+ 'a' => array('href' => '/index?page=5', 'rel' => 'last'),
+ 'last',
+ '/a',
+ '/li'
+ );
+ $this->assertTags($result, $expected);
+ }
+
/**
* testCounter method
*
diff --git a/Cake/View/Helper/PaginatorHelper.php b/Cake/View/Helper/PaginatorHelper.php
index f2417997513..5aad763b0ca 100644
--- a/Cake/View/Helper/PaginatorHelper.php
+++ b/Cake/View/Helper/PaginatorHelper.php
@@ -275,19 +275,19 @@ protected function _toggledLink($text, $enabled, $options, $templates) {
return '';
}
$text = $options['escape'] ? h($text) : $text;
- $paging = $this->params($options['model']);
if (!$enabled) {
return $this->_templater->format($template, [
'text' => $text,
]);
}
+ $paging = $this->params($options['model']);
$url = array_merge(
$options['url'],
['page' => $paging['page'] + $options['step']]
);
- $url = $this->url($url);
+ $url = $this->url($url, $options['model']);
return $this->_templater->format($template, [
'url' => $url,
'text' => $text,
@@ -426,7 +426,7 @@ public function sort($key, $title = null, $options = []) {
);
$vars = [
'text' => $options['escape'] ? h($title) : $title,
- 'url' => $this->url($url),
+ 'url' => $this->url($url, $options['model']),
];
return $this->_templater->format($template, $vars);
}
@@ -435,7 +435,6 @@ public function sort($key, $title = null, $options = []) {
* Merges passed URL options with current pagination state to generate a pagination URL.
*
* @param array $options Pagination/URL options array
- * @param boolean $asArray Return the url as an array, or a URI string
* @param string $model Which model to paginate on
* @return mixed By default, returns a full pagination URL string for use in non-standard contexts (i.e. JavaScript)
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::url
@@ -631,7 +630,6 @@ public function numbers($options = array()) {
$options += $defaults;
$params = (array)$this->params($options['model']) + array('page' => 1);
- unset($options['model']);
if ($params['pageCount'] <= 1) {
return false;
@@ -666,21 +664,21 @@ public function numbers($options = array()) {
for ($i = $start; $i < $params['page']; $i++) {
$vars = [
'text' => $i,
- 'url' => $this->url(['page' => $i]),
+ 'url' => $this->url(['page' => $i], $options['model']),
];
$out .= $this->_templater->format('number', $vars);
}
$out .= $this->_templater->format('current', [
'text' => $params['page'],
- 'url' => $this->url(['page' => $params['page']]),
+ 'url' => $this->url(['page' => $params['page']], $options['model']),
]);
$start = $params['page'] + 1;
for ($i = $start; $i < $end; $i++) {
$vars = [
'text' => $i,
- 'url' => $this->url(['page' => $i]),
+ 'url' => $this->url(['page' => $i], $options['model']),
];
$out .= $this->_templater->format('number', $vars);
}
@@ -688,7 +686,7 @@ public function numbers($options = array()) {
if ($end != $params['page']) {
$vars = [
'text' => $i,
- 'url' => $this->url(['page' => $end]),
+ 'url' => $this->url(['page' => $end], $options['model']),
];
$out .= $this->_templater->format('number', $vars);
}
@@ -710,12 +708,12 @@ public function numbers($options = array()) {
if ($i == $params['page']) {
$out .= $this->_templater->format('current', [
'text' => $params['page'],
- 'url' => $this->url(['page' => $params['page']]),
+ 'url' => $this->url(['page' => $params['page']], $options['model']),
]);
} else {
$vars = [
'text' => $i,
- 'url' => $this->url(['page' => $i]),
+ 'url' => $this->url(['page' => $i], $options['model']),
];
$out .= $this->_templater->format('number', $vars);
}
@@ -756,11 +754,7 @@ public function first($first = '<< first', $options = []) {
(array)$options
);
- $params = array_merge(
- ['page' => 1],
- (array)$this->params($options['model'])
- );
- unset($options['model']);
+ $params = $this->params($options['model']);
if ($params['pageCount'] <= 1) {
return false;
@@ -771,14 +765,14 @@ public function first($first = '<< first', $options = []) {
if (is_int($first) && $params['page'] >= $first) {
for ($i = 1; $i <= $first; $i++) {
$out .= $this->_templater->format('number', [
- 'url' => $this->url(['page' => $i]),
+ 'url' => $this->url(['page' => $i], $options['model']),
'text' => $i
]);
}
} elseif ($params['page'] > 1 && is_string($first)) {
$first = $options['escape'] ? h($first) : $first;
$out .= $this->_templater->format('first', [
- 'url' => $this->url(['page' => 1]),
+ 'url' => $this->url(['page' => 1], $options['model']),
'text' => $first
]);
}
@@ -812,11 +806,7 @@ public function last($last = 'last >>', $options = array()) {
(array)$options
);
- $params = array_merge(
- ['page' => 1],
- (array)$this->params($options['model'])
- );
- unset($options['model']);
+ $params = $this->params($options['model']);
if ($params['pageCount'] <= 1) {
return false;
@@ -828,14 +818,14 @@ public function last($last = 'last >>', $options = array()) {
if (is_int($last) && $params['page'] <= $lower) {
for ($i = $lower; $i <= $params['pageCount']; $i++) {
$out .= $this->_templater->format('number', [
- 'url' => $this->url(['page' => $i]),
+ 'url' => $this->url(['page' => $i], $options['model']),
'text' => $i
]);
}
} elseif ($params['page'] < $params['pageCount'] && is_string($last)) {
$last = $options['escape'] ? h($last) : $last;
$out .= $this->_templater->format('last', [
- 'url' => $this->url(['page' => $params['pageCount']]),
+ 'url' => $this->url(['page' => $params['pageCount']], $options['model']),
'text' => $last
]);
}