Skip to content

Instantly share code, notes, and snippets.

@AD7six
Last active December 20, 2015 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AD7six/6069103 to your computer and use it in GitHub Desktop.
Save AD7six/6069103 to your computer and use it in GitHub Desktop.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch 2.4
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: lib/Cake/Controller/Controller.php
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# app/Controller/PostsController.php
# app/Model/Post.php
# app/Test/Case/Controller/PostsControllerTest.php
# app/Test/Case/Model/PostTest.php
# app/Test/Fixture/PostFixture.php
# app/View/Posts/
# composer.json
diff --git lib/Cake/Controller/Controller.php lib/Cake/Controller/Controller.php
index aefc83f..717ce20 100644
--- lib/Cake/Controller/Controller.php
+++ lib/Cake/Controller/Controller.php
@@ -121,6 +121,31 @@ class Controller extends Object implements CakeEventListener {
protected $_responseClass = 'CakeResponse';
/**
+ * Holds pagination defaults for controller actions. The keys that can be included
+ * in this array are: 'conditions', 'fields', 'order', 'limit', 'page', and 'recursive',
+ * similar to the keys in the second parameter of Model::find().
+ *
+ * Pagination defaults can also be supplied in a model-by-model basis by using
+ * the name of the model as a key for a pagination array:
+ *
+ * {{{
+ * public $paginate = array(
+ * 'Post' => array(...),
+ * 'Comment' => array(...)
+ * );
+ * }}}
+ *
+ * @var array
+ * @link http://book.cakephp.org/view/1231/Pagination
+ */
+ public $paginate = array(
+ 'limit' => 20,
+ 'page' => 1,
+ 'maxLimit' => 100,
+ 'paramType' => 'named'
+ );
+
+/**
* The name of the views subfolder containing views for this controller.
*
* @var string
@@ -398,8 +423,6 @@ class Controller extends Object implements CakeEventListener {
return isset($this->request->params['action']) ? $this->request->params['action'] : '';
case 'params':
return $this->request;
- case 'paginate':
- return $this->Components->load('Paginator')->settings;
}
if (isset($this->{$name})) {
@@ -427,8 +450,6 @@ class Controller extends Object implements CakeEventListener {
return $this->request->params['action'] = $value;
case 'params':
return $this->request->params = $value;
- case 'paginate':
- return $this->Components->load('Paginator')->settings = $value;
}
return $this->{$name} = $value;
}
@@ -1068,10 +1089,14 @@ class Controller extends Object implements CakeEventListener {
* @param array $whitelist List of allowed options for paging
* @return array Model query results
* @link http://book.cakephp.org/2.0/en/controllers.html#Controller::paginate
- * @deprecated Use PaginatorComponent instead
*/
public function paginate($object = null, $scope = array(), $whitelist = array()) {
- return $this->Components->load('Paginator', $this->paginate)->paginate($object, $scope, $whitelist);
+ if (!isset($this->Paginator)) {
+ $this->Paginator = $this->Components->load('Paginator', $this->paginate);
+ } else {
+ $this->Paginator->settings = $this->paginate;
+ }
+ return $this->Paginator->paginate($object, $scope, $whitelist);
}
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment