Skip to content

Commit e31d894

Browse files
committed
Update content about pagination
1 parent 48b3f46 commit e31d894

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

guide/index.rst

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,8 +1588,8 @@ retrieved via the ``getErrors`` method.
15881588
Pagination
15891589
##########
15901590

1591-
Using the ``paginate`` method, you can perform a basic pagination with all the
1592-
data in a table.
1591+
Using the ``paginate`` method, you can perform pagination with all the data in
1592+
a table.
15931593

15941594
Below, we take the first 30 items from the table:
15951595

@@ -1599,6 +1599,38 @@ Below, we take the first 30 items from the table:
15991599
$perPage = 30;
16001600
$data = $model->paginate($page, $perPage); // array
16011601
1602+
Also, it is possible to pass an array to the WHERE clause, as in the example
1603+
below:
1604+
1605+
.. code-block:: php
1606+
1607+
$where = [
1608+
['id', '<', 100], // WHERE `id` < 100
1609+
['author', 'is not null'], // AND `author` IS NOT NULL
1610+
];
1611+
$data = $model->paginate($page, $perPage, $where); // array
1612+
1613+
The following SQL will be appended to the query:
1614+
1615+
.. code-block:: sql
1616+
1617+
WHERE `id` < 100
1618+
AND `author` IS NOT NULL
1619+
1620+
Also, it is possible to order the results by the last parameters:
1621+
1622+
.. code-block:: php
1623+
1624+
$orderBy = 'title'; // Column name
1625+
$orderByDirection = 'asc'; // asc or desc
1626+
$data = $model->paginate(
1627+
$page,
1628+
$perPage,
1629+
$where,
1630+
$orderBy,
1631+
$orderByDirection
1632+
); // array
1633+
16021634
After calling the ``paginate`` method, the ``$pager`` property will have an
16031635
instance of the **Framework\Pagination\Pager** class, which can be obtained by
16041636
the ``getPager`` method.

0 commit comments

Comments
 (0)