Skip to content

Commit c72def4

Browse files
committed
Moved exception throwing to after paging info it set for request.
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
1 parent a9ca1bd commit c72def4

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lib/Cake/Controller/Component/PaginatorComponent.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,6 @@ public function paginate($object = null, $scope = array(), $whitelist = array())
212212
$pageCount = intval(ceil($count / $limit));
213213
$requestedPage = $page;
214214
$page = max(min($page, $pageCount), 1);
215-
if ($requestedPage > $page) {
216-
throw new NotFoundException();
217-
}
218215

219216
$paging = array(
220217
'page' => $page,
@@ -237,6 +234,10 @@ public function paginate($object = null, $scope = array(), $whitelist = array())
237234
array($object->alias => $paging)
238235
);
239236

237+
if ($requestedPage > $page) {
238+
throw new NotFoundException();
239+
}
240+
240241
if (
241242
!in_array('Paginator', $this->Controller->helpers) &&
242243
!array_key_exists('Paginator', $this->Controller->helpers)

lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,6 @@ public function testOutOfVeryBigPageNumberGetsClamped() {
919919
/**
920920
* testOutOfRangePageNumberAndPageCountZero
921921
*
922-
* @expectedException NotFoundException
923922
* @return void
924923
*/
925924
public function testOutOfRangePageNumberAndPageCountZero() {
@@ -933,7 +932,17 @@ public function testOutOfRangePageNumberAndPageCountZero() {
933932
$Controller->paginate = array(
934933
'conditions' => array('PaginatorControllerPost.id >' => 100)
935934
);
936-
$Controller->Paginator->paginate('PaginatorControllerPost');
935+
936+
try {
937+
$Controller->Paginator->paginate('PaginatorControllerPost');
938+
$this->fail();
939+
} catch (NotFoundException $e) {
940+
$this->assertEquals(
941+
1,
942+
$Controller->request->params['paging']['PaginatorControllerPost']['page'],
943+
'Page number should not be 0'
944+
);
945+
}
937946
}
938947

939948
/**

0 commit comments

Comments
 (0)