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..c90b8ba5ae 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' => ['favorites' => [$user]], + + // Use scoped query string parameters. + 'scope' => 'favorites', + ] + ); + $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.