@raven_corwin
To use Phalcon's built-in pagination functionality:
- Initialize the Paginator object by creating an instance of the PhalconPaginatorAdapterModel class.
use PhalconPaginatorAdapterModel as PaginatorModel;
$paginator = new PaginatorModel(
[
"data" => YourModel::find(),
"limit" => 10,
"page" => $currentPage,
]
);
- Set the data to be paginated by using the data key. In the above example, the YourModel::find() method is used to fetch the data to be paginated.
- Set the limit of data to be displayed per page using the limit key.
- Set the current page using the page key.
- Fetch the paginated data using the getPaginate() method of the Paginator object.
$page = $paginator->getPaginate();
- Loop through the paginated data to display it on your view.
tag->linkTo(['page=' . $page->before, 'Previous']) ?>
tag->linkTo(['page=' . $page->next, 'Next']) ?>
items as $item) { ?>
Field 1
Field 2
Field 3
field1 ?>
field2 ?>
field3 ?>
- Display the pagination links using the before and next properties of the getPaginate() method.
Note: getPaginate()
returns an object that contains the following properties:
- before: The previous page number, or NULL if there is no previous page.
- next: The next page number, or NULL if there is no next page.
- last: The last page number.
- current: The current page number.
- total_pages: The total number of pages.
- total_items: The total number of items.