Skip to content

Commit

Permalink
Moved exception throwing to after paging info it set for request.
Browse files Browse the repository at this point in the history
This fixes the regression caused in 2096d3f. When catching exception
thrown by PaginatorComponent::paginate() in controller, developer again
has access to paging info in request object.

Closes #2402
  • Loading branch information
ADmad committed Nov 30, 2013
1 parent a9ca1bd commit c72def4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/Cake/Controller/Component/PaginatorComponent.php
Expand Up @@ -212,9 +212,6 @@ public function paginate($object = null, $scope = array(), $whitelist = array())
$pageCount = intval(ceil($count / $limit));
$requestedPage = $page;
$page = max(min($page, $pageCount), 1);
if ($requestedPage > $page) {
throw new NotFoundException();
}

$paging = array(
'page' => $page,
Expand All @@ -237,6 +234,10 @@ public function paginate($object = null, $scope = array(), $whitelist = array())
array($object->alias => $paging)
);

if ($requestedPage > $page) {
throw new NotFoundException();
}

if (
!in_array('Paginator', $this->Controller->helpers) &&
!array_key_exists('Paginator', $this->Controller->helpers)
Expand Down
13 changes: 11 additions & 2 deletions lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php
Expand Up @@ -919,7 +919,6 @@ public function testOutOfVeryBigPageNumberGetsClamped() {
/**
* testOutOfRangePageNumberAndPageCountZero
*
* @expectedException NotFoundException
* @return void
*/
public function testOutOfRangePageNumberAndPageCountZero() {
Expand All @@ -933,7 +932,17 @@ public function testOutOfRangePageNumberAndPageCountZero() {
$Controller->paginate = array(
'conditions' => array('PaginatorControllerPost.id >' => 100)
);
$Controller->Paginator->paginate('PaginatorControllerPost');

try {
$Controller->Paginator->paginate('PaginatorControllerPost');
$this->fail();
} catch (NotFoundException $e) {
$this->assertEquals(
1,
$Controller->request->params['paging']['PaginatorControllerPost']['page'],
'Page number should not be 0'
);
}
}

/**
Expand Down

0 comments on commit c72def4

Please sign in to comment.