@@ -1588,8 +1588,8 @@ retrieved via the ``getErrors`` method.
1588
1588
Pagination
1589
1589
##########
1590
1590
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.
1593
1593
1594
1594
Below, we take the first 30 items from the table:
1595
1595
@@ -1599,6 +1599,38 @@ Below, we take the first 30 items from the table:
1599
1599
$perPage = 30;
1600
1600
$data = $model->paginate($page, $perPage); // array
1601
1601
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
+
1602
1634
After calling the ``paginate `` method, the ``$pager `` property will have an
1603
1635
instance of the **Framework\P agination\P ager ** class, which can be obtained by
1604
1636
the ``getPager `` method.
0 commit comments