mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Allowing paginate() to send any extra parameters to the find call, and updating it to use new find notation.
Updating test in Containable to reflect how to properly use pagination: just set your 'contain' setting as you do with other pagination parameters, for example: var $paginate = array('Article' => array('conditions' => ..., 'contain' => array( ... )); and then do your normal paginate(), without having to set reset to false nor call resetBindings(). Check the test case for an actual example. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7010 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
d1d06eb4fe
commit
8f92952d46
2 changed files with 7 additions and 8 deletions
|
@ -979,10 +979,11 @@ class Controller extends Object {
|
|||
}
|
||||
$recursive = $object->recursive;
|
||||
|
||||
$extra = array_diff_key($defaults, compact('conditions', 'fields', 'order', 'limit', 'page', 'recursive'));
|
||||
if (method_exists($object, 'paginateCount')) {
|
||||
$count = $object->paginateCount($conditions, $recursive);
|
||||
} else {
|
||||
$count = $object->findCount($conditions, $recursive);
|
||||
$count = $object->find('count', array_merge(compact('conditions', 'recursive'), $extra));
|
||||
}
|
||||
$pageCount = intval(ceil($count / $limit));
|
||||
|
||||
|
@ -995,7 +996,7 @@ class Controller extends Object {
|
|||
if (method_exists($object, 'paginate')) {
|
||||
$results = $object->paginate($conditions, $fields, $order, $limit, $page, $recursive);
|
||||
} else {
|
||||
$results = $object->findAll($conditions, $fields, $order, $limit, $page, $recursive);
|
||||
$results = $object->find('all', array_merge(compact('conditions', 'fields', 'order', 'limit', 'page', 'recursive'), $extra));
|
||||
}
|
||||
$paging = array(
|
||||
'page' => $page,
|
||||
|
|
|
@ -2976,14 +2976,12 @@ class ContainableTest extends CakeTestCase {
|
|||
$Controller->passedArgs[] = '1';
|
||||
$Controller->params['url'] = array();
|
||||
$Controller->constructClasses();
|
||||
$Controller->paginate = array('Article' => array('fields' => array('title')));
|
||||
$Controller->Article->contain(false, array('User(user)'));
|
||||
$Controller->paginate = array('Article' => array('fields' => array('title'), 'contain' => array('User(user)')));
|
||||
$result = $Controller->paginate('Article');
|
||||
$Controller->Article->resetBindings();
|
||||
$expected = array(
|
||||
array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano')),
|
||||
array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry')),
|
||||
array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano')),
|
||||
array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
|
||||
array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry', 'id' => 3)),
|
||||
array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue