Updating Controller::paginate(). Custom paginate() and paginateCount() methods now receive $extra params similar to find('all') and find('count') do. Allows the use of things like 'contain' with custom paginate() methods.

Test case added. Closes #5433 refs #5123.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7627 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2008-09-19 00:46:20 +00:00
parent 8fadcbafea
commit 768e25c4fd
2 changed files with 47 additions and 2 deletions

View file

@ -979,7 +979,7 @@ class Controller extends Object {
));
if (method_exists($object, 'paginateCount')) {
$count = $object->paginateCount($conditions, $recursive);
$count = $object->paginateCount($conditions, $recursive, $extra);
} else {
$parameters = compact('conditions');
if ($recursive != $object->recursive) {
@ -996,7 +996,7 @@ class Controller extends Object {
}
if (method_exists($object, 'paginate')) {
$results = $object->paginate($conditions, $fields, $order, $limit, $page, $recursive);
$results = $object->paginate($conditions, $fields, $order, $limit, $page, $recursive, $extra);
} else {
$parameters = compact('conditions', 'fields', 'order', 'limit', 'page');
if ($recursive != $object->recursive) {

View file

@ -127,6 +127,40 @@ class ControllerComment extends CakeTestModel {
*/
var $alias = 'ControllerComment';
}
class ControllerPaginateModel extends CakeTestModel {
/**
* name property
*
* @var string
* @access public
*/
var $name = 'ControllerPaginateModel';
/**
* useTable property
*
* @var string'
* @access public
*/
var $useTable = 'comments';
/**
* paginate method
*
* @return void
* @access public
**/
function paginate($conditions, $fields, $order, $limit, $page, $recursive, $extra) {
$this->extra = $extra;
}
/**
* paginateCount
*
* @access public
* @return void
*/
function paginateCount($conditions, $recursive, $extra) {
$this->extraCount = $extra;
}
}
/**
* NameTest class
*
@ -402,6 +436,17 @@ class ControllerTest extends CakeTestCase {
$result = $Controller->paginate('ControllerPost');
$this->assertEqual(Set::extract($result, '{n}.ControllerPost.id'), array(2, 3));
$this->assertEqual($Controller->ControllerPost->lastQuery['conditions'], array('ControllerPost.id > ' => '1'));
$Controller =& new Controller();
$Controller->uses = array('ControllerPaginateModel');
$Controller->params['url'] = array();
$Controller->constructClasses();
$Controller->paginate = array(
'ControllerPaginateModel' => array('contain' => array('ControllerPaginateModel'), 'group' => 'Comment.author_id'));
$result = $Controller->paginate('ControllerPaginateModel');
$expected = array('contain' => array('ControllerPaginateModel'), 'group' => 'Comment.author_id');
$this->assertEqual($Controller->ControllerPaginateModel->extra, $expected);
$this->assertEqual($Controller->ControllerPaginateModel->extraCount, $expected);
}
/**
* testDefaultPaginateParams method