scrnr/pagination

Pagination library in PHP

v1.0.0 2023-04-28 09:22 UTC

This package is auto-updated.

Last update: 2024-11-28 14:39:43 UTC


README

Packagist PHP Version Packagist Version Packagist License

Table Of Contents

Description 🔝

This is a simple and flexible PHP library for creating pagination in your web applications. It allows you to easily paginate large sets of data and display them in smaller, more manageable chunks.

Installation 🔝

You can install the library using Composer. Simply add the following lines to your composer.json file and run composer install:

"require": {
  "scrnr/pagination": "*"
}

Or you can use this command:

composer require scrnr/pagination

Usage 🔝

To use the pagination library in your application, you need to include the Composer autoload file and create a new instance. After creating an instance, you can call the getPagination() method, passing an optional array of options as a parameter. This method to generate a string representation of the pagination links.

Here is an example of usage

<?php

// Include the namespace
use Scrnr\Pagination\Pagination;

// Require the Composer autoload file
require_once __DIR__ . '/vendor/autoload.php';

// Create a new Pagination instance
$pagination = new Pagination();

// Pagination settings
$options = [
  'isGetPagination' => true,
  'currentPage' => (int) ($_GET['page'] ?? 1),
  'limitItems' => 50,
  'limitPages' => 15,
  'totalItems' => 500,
];

// Get the pagination links
$links = $pagination->getPagination($options);

// Display the pagination links
echo $links;

Output

<nav class='pagination' id='pagination'>
  <ul class='pagination__ul'>
    <li class='pagination__item'>
      <a href='/?page=1' class='pagination__link active'>1</a>
    </li>
    <li class='pagination__item'>
      <a href='/?page=2' class='pagination__link next'>2</a>
    </li>
    <li class='pagination__item'>
      <a href='/?page=3' class='pagination__link'>3</a>
    </li>
    <li class='pagination__item'>
      <a href='/?page=4' class='pagination__link'>4</a>
    </li>
    <li class='pagination__item'>
      <a href='/?page=5' class='pagination__link'>5</a>
    </li>
    <li class='pagination__item'>
      <a href='/?page=6' class='pagination__link'>6</a>
    </li>
    <li class='pagination__item'>
      <a href='/?page=7' class='pagination__link'>7</a>
    </li>
    <li class='pagination__item'>
      <a href='/?page=8' class='pagination__link'>8</a>
    </li>
    <li class='pagination__item'>
      <a href='/?page=9' class='pagination__link'>9</a>
    </li>
    <li class='pagination__item'>
      <a href='/?page=10' class='pagination__link'>10</a>
    </li>
    </ul>
</nav>

In this example, we first include the namespace for the Pagination class. We then require the Composer autoload file, which loads the necessary classes and files for our project. Finally, we create a new instance of the Pagination class and use it to generate pagination.

Customization Pagination Settings 🔝

You can customize the pagination settings by passing an array of options to the getPagination() method. The following options are available:

NOTES

Conclusion 🔝

The Pagination library is a simple and flexible solution for paginating large datasets. It is easy to use, easy to customize and compatible with any PHP project.

Author 🔝

👤 GitHub: scrnr

License 🔝

This library is released under the MIT License. Please review the LICENSE file for more information.