Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix page 0 issue.

Refs #2929
  • Loading branch information...
commit d1819dcabb31108751ff5fb630965b9b660fb65b 1 parent 15a423a
Mark Story markstory authored
4 lib/Cake/Controller/Component/PaginatorComponent.php
View
@@ -184,7 +184,7 @@ public function paginate($object = null, $scope = array(), $whitelist = array())
$count = $object->find('count', array_merge($parameters, $extra));
}
$pageCount = intval(ceil($count / $limit));
- $page = min($page, $pageCount);
+ $page = max(min($page, $pageCount), 1);
$paging = array(
'page' => $page,
@@ -375,7 +375,7 @@ public function checkLimit($options) {
if (empty($options['limit']) || $options['limit'] < 1) {
$options['limit'] = 1;
}
- $options['limit'] = min((int)$options['limit'], $options['maxLimit']);
+ $options['limit'] = min($options['limit'], $options['maxLimit']);
return $options;
}
16 lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php
View
@@ -725,7 +725,21 @@ public function testOutOfRangePageNumberGetsClamped() {
$Controller->constructClasses();
$Controller->PaginatorControllerPost->recursive = 0;
$Controller->Paginator->paginate('PaginatorControllerPost');
- $this->assertEquals(1, $Controller->request->params['paging']['PaginatorControllerPost']['page']);
+ $this->assertEquals(
+ 1,
+ $Controller->request->params['paging']['PaginatorControllerPost']['page'],
+ 'Super big page number should be capped to max number of pages'
+ );
+
+ $Controller->paginate = array(
+ 'conditions' => array('PaginatorControllerPost.id >' => 100)
+ );
+ $Controller->Paginator->paginate('PaginatorControllerPost');
+ $this->assertEquals(
+ 1,
+ $Controller->request->params['paging']['PaginatorControllerPost']['page'],
+ 'Page number should not be 0'
+ );
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.