1 | <?php |
||
5 | class Paginator |
||
6 | { |
||
7 | private $config; |
||
8 | private $countQuery; |
||
9 | private $paginationQuery; |
||
10 | private $totalItems; |
||
11 | private $totalPages; |
||
12 | |||
13 | public function __construct($query, $config, $db) |
||
19 | |||
20 | /** |
||
21 | * create two queries out of the given query : |
||
22 | * - query to count the rows |
||
23 | * - query to paginate the data. |
||
24 | * |
||
25 | * @todo handle the case when the query already have the limit clause. |
||
26 | */ |
||
27 | public function craftQuries($query) |
||
36 | |||
37 | public function performQueries($db) |
||
43 | |||
44 | public function getCurrentItems() |
||
48 | |||
49 | public function getCurrentPage() |
||
53 | |||
54 | public function getTotalItem() |
||
58 | |||
59 | public function getRowsPerPage() |
||
63 | |||
64 | public function getTotalPages() |
||
68 | } |
||
69 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: