mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
commit
b8268cd055
2 changed files with 15 additions and 5 deletions
|
@ -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)
|
||||
|
|
|
@ -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'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue