From 1aa60fa93ef8914dc6635c038e45678d8fb5224e Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sun, 18 Jun 2017 22:09:15 -0400 Subject: [PATCH 1/5] Document standalone paginator. Include an example of usage in View Cells. Refs cakephp/cakephp#10718 --- en/appendices/3-5-migration-guide.rst | 31 ++++++++++++------- en/views/cells.rst | 44 +++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/en/appendices/3-5-migration-guide.rst b/en/appendices/3-5-migration-guide.rst index d7cc681e2d..f50c3753e9 100644 --- a/en/appendices/3-5-migration-guide.rst +++ b/en/appendices/3-5-migration-guide.rst @@ -136,6 +136,26 @@ Console allows you to set the command name used when generating help output. Defaults to ``cake``. +Datasource +---------- + +* ``Cake\Datasource\SchemaInterface`` was added. +* New abstract types were added for ``smallinteger`` and ``tinyinteger``. + Existing ``SMALLINT`` and ``TINYINT`` columns will now be reflected as these + new abstract types. ``TINYINT(1)`` columns will continue to be treated as + boolean columns in MySQL. +* ``Cake\Datasource\PaginatorInterface`` was added. The ``PaginatorComponent`` + now uses this interface to interact with paginators. This allows other + ORM-like implementations to be paginated by the component. +* ``Cake\Datasource\Paginator`` was added to paginate ORM/Database Query + instances. + +Event +----- + +* ``Cake\Event\EventManager::on()`` and ``off()`` methods are now chainable + making it simpler to set multiple events at once. + Http ---- @@ -153,20 +173,9 @@ Http * ``Cake\Http\Client::addCookie()`` was added to make it easy to add cookies to a client instance. -Event ------ - -* ``Cake\Event\EventManager::on()`` and ``off()`` methods are now chainable - making it simpler to set multiple events at once. - ORM --- -* ``Cake\Datasource\SchemaInterface`` was added. -* New abstract types were added for ``smallinteger`` and ``tinyinteger``. - Existing ``SMALLINT`` and ``TINYINT`` columns will now be reflected as these - new abstract types. ``TINYINT(1)`` columns will continue to be treated as - boolean columns in MySQL. * ``Cake\ORM\Query::contain()`` now allows you to call it without the wrapping array when containing a single association. ``contain('Comments', function () { ... });`` will now work. This makes ``contain()`` consistent with other diff --git a/en/views/cells.rst b/en/views/cells.rst index 3087473d61..730923b8ef 100644 --- a/en/views/cells.rst +++ b/en/views/cells.rst @@ -205,3 +205,47 @@ name will be used. do not share context with the main template / layout. Each cell is self-contained and only has access to variables passed as arguments to the ``View::cell()`` call. + + +Paginating Data inside a Cell +============================= + +Creating a cell that renders a paginated result set can be done by leveraging +the ``Paginator`` class of the ORM. An example of paginating a user's favorite +messages could look like:: + + namespace App\View\Cell; + + use Cake\View\Cell; + use Cake\Datasource\Paginator; + + class FavoritesCell extends Cell + { + public function display($user) + { + $this->loadModel('Messages'); + + // Create a paginator + $paginator = new Paginator() + + // Paginate the model + $results = $paginator->paginate( + $this->Messages, + $this->request->getQueryParams(), + [ + // Use a parameterized custom finder. + 'finder' => ['favourites' => [$user]] + + // Use scoped query string parameters. + 'scope' => 'favourites' + ] + ); + $this->set('favorites', $results); + } + } + +The above cell would paginate the ``Messages`` model using :ref:`scoped +pagination parameters `. + +.. versionadded:: 3.5.0 + ``Cake\Datasource\Paginator`` was added in 3.5.0. From 55c9f0fbf89d16c31fdc9985022952609a9679b6 Mon Sep 17 00:00:00 2001 From: ADmad Date: Mon, 19 Jun 2017 09:29:09 +0530 Subject: [PATCH 2/5] Fix spelling inconsistency. --- en/views/cells.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/en/views/cells.rst b/en/views/cells.rst index 730923b8ef..a94b977654 100644 --- a/en/views/cells.rst +++ b/en/views/cells.rst @@ -240,7 +240,7 @@ messages could look like:: 'scope' => 'favourites' ] ); - $this->set('favorites', $results); + $this->set('favourites', $results); } } From 0d6d7679be888871db74eb1ecb4722ffb860c5e1 Mon Sep 17 00:00:00 2001 From: ADmad Date: Mon, 19 Jun 2017 09:31:46 +0530 Subject: [PATCH 3/5] Use US spelling of "favorites" --- en/views/cells.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/en/views/cells.rst b/en/views/cells.rst index a94b977654..bb98328851 100644 --- a/en/views/cells.rst +++ b/en/views/cells.rst @@ -234,13 +234,13 @@ messages could look like:: $this->request->getQueryParams(), [ // Use a parameterized custom finder. - 'finder' => ['favourites' => [$user]] + 'finder' => ['favorites' => [$user]] // Use scoped query string parameters. - 'scope' => 'favourites' + 'scope' => 'favorites' ] ); - $this->set('favourites', $results); + $this->set('favorites', $results); } } From 676cbbe075f5040ba88755efdf5c80b676127261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=BCrth?= Date: Mon, 19 Jun 2017 16:59:52 +0200 Subject: [PATCH 4/5] Missing semicolon --- en/views/cells.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/en/views/cells.rst b/en/views/cells.rst index bb98328851..9465036438 100644 --- a/en/views/cells.rst +++ b/en/views/cells.rst @@ -226,7 +226,7 @@ messages could look like:: $this->loadModel('Messages'); // Create a paginator - $paginator = new Paginator() + $paginator = new Paginator(); // Paginate the model $results = $paginator->paginate( From b3f37997604a4b2e9f6877b5c6c5c5db112f8696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=BCrth?= Date: Mon, 19 Jun 2017 17:01:02 +0200 Subject: [PATCH 5/5] Missing comma --- en/views/cells.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/en/views/cells.rst b/en/views/cells.rst index 9465036438..c90b8ba5ae 100644 --- a/en/views/cells.rst +++ b/en/views/cells.rst @@ -234,10 +234,10 @@ messages could look like:: $this->request->getQueryParams(), [ // Use a parameterized custom finder. - 'finder' => ['favorites' => [$user]] + 'finder' => ['favorites' => [$user]], // Use scoped query string parameters. - 'scope' => 'favorites' + 'scope' => 'favorites', ] ); $this->set('favorites', $results);