Adding lower bound for page numbers in Controller::paginate() (Ticket #3683)

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6133 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2007-12-08 08:54:27 +00:00
parent 0b9f2c1b9d
commit e56b92255f
2 changed files with 7 additions and 0 deletions

View file

@ -952,6 +952,8 @@ class Controller extends Object {
if ($page == 'last' || $page >= $pageCount) {
$options['page'] = $page = $pageCount;
} elseif (intval($page) < 1) {
$options['page'] = $page = 1;
}
if (method_exists($object, 'paginate')) {

View file

@ -96,6 +96,11 @@ class ControllerTest extends CakeTestCase {
$Controller->uses[0] = 'Plugin.ControllerPost';
$results = Set::extract($Controller->paginate(), '{n}.ControllerPost.id');
$this->assertEqual($results, array(1, 2, 3));
$Controller->passedArgs = array('page' => '-1');
$results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
$this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1);
$this->assertEqual($results, array(1, 2, 3));
}
}