Merge pull request #2408 from ADmad/2.4-paginator-exception

Moved exception throwing to after paging info it set for request.

Fixes #2402
This commit is contained in:
Mark Story 2013-11-30 14:17:12 -08:00
commit b8268cd055
2 changed files with 15 additions and 5 deletions

View file

@ -212,9 +212,6 @@ class PaginatorComponent extends Component {
$pageCount = intval(ceil($count / $limit));
$requestedPage = $page;
$page = max(min($page, $pageCount), 1);
if ($requestedPage > $page) {
throw new NotFoundException();
}
$paging = array(
'page' => $page,
@ -237,6 +234,10 @@ class PaginatorComponent extends Component {
array($object->alias => $paging)
);
if ($requestedPage > $page) {
throw new NotFoundException();
}
if (
!in_array('Paginator', $this->Controller->helpers) &&
!array_key_exists('Paginator', $this->Controller->helpers)

View file

@ -919,7 +919,6 @@ class PaginatorComponentTest extends CakeTestCase {
/**
* testOutOfRangePageNumberAndPageCountZero
*
* @expectedException NotFoundException
* @return void
*/
public function testOutOfRangePageNumberAndPageCountZero() {
@ -933,7 +932,17 @@ class PaginatorComponentTest extends CakeTestCase {
$Controller->paginate = array(
'conditions' => array('PaginatorControllerPost.id >' => 100)
);
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'
);
}
}
/**