{"id":17122257,"url":"https://github.com/s-damian/damian-pagination-php","last_synced_at":"2025-06-27T10:07:05.336Z","repository":{"id":56778433,"uuid":"525032095","full_name":"s-damian/damian-pagination-php","owner":"s-damian","description":"PHP Pagination Library - Open Source Paginator Package","archived":false,"fork":false,"pushed_at":"2024-12-18T07:39:48.000Z","size":1294,"stargazers_count":3,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-27T10:06:30.783Z","etag":null,"topics":["paginate","pagination","pagination-generator","pagination-library","pagination-php","paginator","php-library","php-package","php-pagination","php8","php84"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/s-damian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-08-15T15:07:12.000Z","updated_at":"2025-06-02T16:52:45.000Z","dependencies_parsed_at":"2024-03-03T09:32:14.243Z","dependency_job_id":"564aadf4-5f8e-4112-8e2c-29a06682633a","html_url":"https://github.com/s-damian/damian-pagination-php","commit_stats":{"total_commits":101,"total_committers":3,"mean_commits":"33.666666666666664","dds":"0.16831683168316836","last_synced_commit":"6006f656931e6fdb6e7980a866143f11688267b3"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/s-damian/damian-pagination-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-damian%2Fdamian-pagination-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-damian%2Fdamian-pagination-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-damian%2Fdamian-pagination-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-damian%2Fdamian-pagination-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/s-damian","download_url":"https://codeload.github.com/s-damian/damian-pagination-php/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-damian%2Fdamian-pagination-php/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262235779,"owners_count":23279566,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["paginate","pagination","pagination-generator","pagination-library","pagination-php","paginator","php-library","php-package","php-pagination","php8","php84"],"created_at":"2024-10-14T18:07:05.623Z","updated_at":"2025-06-27T10:07:05.306Z","avatar_url":"https://github.com/s-damian.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\r\n\u003ca href=\"https://github.com/s-damian/damian-pagination-php\"\u003e\r\n\u003cimg src=\"https://raw.githubusercontent.com/s-damian/medias/main/package-logos/damian-pagination-php.png\" width=\"400\"\u003e\r\n\u003c/a\u003e\r\n\u003c/p\u003e\r\n\r\n# PHP Pagination Library - Open Source\r\n\r\n[![Tests](https://github.com/s-damian/damian-pagination-php/actions/workflows/tests.yml/badge.svg)](https://github.com/s-damian/damian-pagination-php/actions/workflows/tests.yml)\r\n[![Static analysis](https://github.com/s-damian/damian-pagination-php/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/s-damian/damian-pagination-php/actions/workflows/static-analysis.yml)\r\n[![Total Downloads](https://poser.pugx.org/s-damian/damian-pagination-php/downloads)](https://packagist.org/packages/s-damian/damian-pagination-php)\r\n[![Latest Stable Version](https://poser.pugx.org/s-damian/damian-pagination-php/v/stable)](https://packagist.org/packages/s-damian/damian-pagination-php)\r\n[![License](https://poser.pugx.org/s-damian/damian-pagination-php/license)](https://packagist.org/packages/s-damian/damian-pagination-php)\r\n\r\n## Damian Pagination PHP - Open Source Pagination\r\n\r\n### Introduction - Damian Pagination PHP\r\n\r\nDamian Pagination PHP is an open-source PHP library designed to provide simple yet comprehensive pagination functionality.\r\n\r\nThis pagination library is compatible with all PHP projects (with or without MVC frameworks) and is also compatible with Bootstrap 5 CSS.\r\n\r\n### Key Features\r\n\r\n- Simple library for **pagination**.\r\n- Customizable **per page** options.\r\n- Support for multiple **languages**.\r\n- Compatible with **Bootstrap 5**.\r\n\r\n\u003e Paginate easily without limits 🚀\r\n\r\n### Basic Example\r\n\r\n```php\r\n\u003c?php\r\n\r\n$pagination = new \\DamianPaginationPhp\\Pagination();\r\n\r\n$pagination-\u003epaginate($countElements);\r\n\r\n$limit = $pagination-\u003egetLimit();\r\n$offset = $pagination-\u003egetOffset();\r\n\r\necho $pagination-\u003erender();\r\necho $pagination-\u003eperPageForm();\r\n```\r\n\r\n### Author\r\n\r\nThis package is developed by [Stephen Damian](https://github.com/s-damian).\r\n\r\n### Requirements\r\n\r\n- PHP `8.0` || `8.1` || `8.2` || `8.3` || `8.4`\r\n\r\n\r\n## Summary\r\n\r\n- [Introduction](#introduction)\r\n- [Installation](#installation)\r\n- [Pagination Instance Methods](#pagination-instance-methods)\r\n- [Examples](#examples)\r\n  - [Simple Example](#simple-example)\r\n  - [Example With SQL Queries](#example-with-sql-queries)\r\n  - [Example With a List of Files of a Directory](#example-with-a-list-of-files-of-a-directory)\r\n- [Instance Options](#instance-options)\r\n- [Language Configuration](#language-configuration)\r\n- [Support](#support)\r\n- [License](#license)\r\n\r\n\r\n## Introduction\r\n\r\nThis Open Source pagination contains PHP files, and one CSS style sheet.\r\n\r\nAn example of a CSS style sheet is in `vendor/s-damian/damian-pagination-php/src/css` directory. You can edit them according to your needs.\r\n\r\nThis pagination library also allows you to generate a **per page** form. This will generate an HTML `\u003cform\u003e` tag with a `\u003cselect\u003e` element and clickable options.\r\n\r\n\r\n## Installation\r\n\r\n### With Composer\r\n\r\n```\r\ncomposer require s-damian/damian-pagination-php\r\n```\r\n\r\n### Without Composer\r\n\r\nIf you do not use Composer, you must manually require the necessary files before using this package. Example:\r\n\r\n```php\r\n\u003c?php\r\n\r\nrequire_once './your-path/damian-pagination-php/src/DamianPaginationPhp/bootstrap/load.php';\r\n```\r\n\r\n\r\n## Pagination Instance Methods\r\n\r\n| Return type    | Method                           | Description                                                               |\r\n| -------------- | -------------------------------- | ------------------------------------------------------------------------- |\r\n| void           | __construct(array $options = []) | Constructor.                                                              |\r\n| void           | paginate(int $count)             | Activate the pagination.                                                  |\r\n| null or int    | getLimit()                       | LIMIT: Number of items to retrieve.                                       |\r\n| null or int    | getOffset()                      | OFFSET: Starting point for the LIMIT.                                       |\r\n| int            | getCount()                       | Determine the total number of matching items in the data store.           |\r\n| int            | getCountOnCurrentPage()          | Get the number of items for the current page.                             |\r\n| int            | getFrom()                        | Get the result number of the first item in the results.                   |\r\n| int            | getTo()                          | Get the result number of the last item in the results.                    |\r\n| int            | getCurrentPage()                 | Get the current page number.                                              |\r\n| int            | getNbPages()                     | Get the page number of the last available page (number of pages).         |\r\n| int            | getPerPage()                     | The number of items to be shown per page.                                 |\r\n| bool           | hasPages()                       | Determine if there are enough items to split into multiple pages.         |\r\n| bool           | hasMorePages()                   | Determine if there are more items in the data store.                      |\r\n| bool           | isFirstPage()                    | Determine if the paginator is on the first page.                          |\r\n| bool           | isLastPage()                     | Determine if the paginator is on the last page.                           |\r\n| bool           | isPage(int $pageNb)              | Determine if the paginator is on a given page number.                     |\r\n| null or string | getPreviousPageUrl()             | Get the URL for the previous page.                                        |\r\n| null or string | getNextPageUrl()                 | Get the URL for the next page.                                            |\r\n| string         | getFirstPageUrl()                | Get the URL for the first page.                                           |\r\n| string         | getLastPageUrl()                 | Get the URL for the last page.                                            |\r\n| string         | getUrl(int $pageNb)              | Get the URL for a given page number.                                      |\r\n| string         | render()                         | Make the rendering of the pagination in HTML format.                      |\r\n| string         | perPageForm(array $options = []) | Make the rendering of the per page in HTML format.                        |\r\n\r\n\r\n## Examples\r\n\r\n### Simple Example\r\n\r\n```php\r\n\u003c?php\r\n\r\nuse DamianPaginationPhp\\Pagination;\r\n\r\n$pagination = new Pagination();\r\n\r\n$pagination-\u003epaginate($countElements);\r\n\r\n$limit = $pagination-\u003egetLimit();\r\n$offset = $pagination-\u003egetOffset();\r\n\r\n// Here your SQL query with $limit and $offset\r\n\r\n// Then your listing of elements with a loop\r\n\r\necho $pagination-\u003erender();\r\necho $pagination-\u003eperPageForm();\r\n```\r\n\r\n#### Example rendering of pagination with Bootstrap 5:\r\n\r\n[![Damian Pagination PHP Bootstrap 5 Example](https://raw.githubusercontent.com/s-damian/medias/main/packages/damian-pagination-php-bootstrap-5-example.webp)](https://github.com/s-damian/larasort)\r\n\r\n### Example With SQL Queries\r\n\r\n```php\r\n\u003c?php\r\n\r\nuse DamianPaginationPhp\\Pagination;\r\n\r\n// Count articles in DB\r\nfunction countArticles(): int\r\n{\r\n    $sql = \"SELECT COUNT(*) AS nb FROM articles\";\r\n    $query = db()-\u003equery($sql);\r\n    $result = $query-\u003efetch();\r\n    \r\n    return $result-\u003enb;\r\n}\r\n\r\n// Collect articles from DB\r\nfunction findArticles($limit, $offset)\r\n{\r\n    $sql = \"SELECT * FROM articles LIMIT ? OFFSET ?\";\r\n    $query = db()-\u003eprepare($sql);\r\n    $query-\u003ebindValue(1, $limit, PDO::PARAM_INT);\r\n    $query-\u003ebindValue(2, $offset, PDO::PARAM_INT);\r\n    $query-\u003eexecute();\r\n\r\n    return $query;\r\n}\r\n\r\n// Creating an object Pagination\r\n$pagination = new Pagination();\r\n\r\n// Paginate\r\n$pagination-\u003epaginate(countArticles());\r\n\r\n$limit = $pagination-\u003egetLimit();\r\n$offset = $pagination-\u003egetOffset();\r\n\r\n$articles = findArticles($limit, $offset);\r\n\r\n// Show elements one by one that are retrieved from the database\r\nforeach ($articles as $article) {\r\n    echo htmlspecialchars($article-\u003etitle);\r\n}\r\n\r\n// Show the Pagination\r\necho $pagination-\u003erender();\r\n// Show the per page\r\necho $pagination-\u003eperPageForm();\r\n```\r\n\r\nThe `db()` function must be defined to return a database connection instance, such as PDO.\r\n\r\nDepending on your needs, you can also use this library with your favorite ORM.\r\n\r\n### Example With a List of Files of a Directory\r\n\r\n```php\r\n\u003c?php\r\n\r\nuse DamianPaginationPhp\\Pagination;\r\n\r\n$scandir = scandir('your_path_upload');\r\n\r\n$listFilesFromPath = [];\r\n$count = 0;\r\nforeach ($scandir as $f) {\r\n    if ($f !== '.' \u0026\u0026 $f !== '..') {\r\n        $listFilesFromPath[] = $f;\r\n        $count++;\r\n    }\r\n}\r\n\r\n// Creating an object Pagination\r\n$pagination = new Pagination();\r\n\r\n// Paginate\r\n$pagination-\u003epaginate($count);\r\n\r\n$limit = $pagination-\u003egetLimit();\r\n$offset = $pagination-\u003egetOffset();\r\n\r\n// Listing\r\n$files = array_slice($listFilesFromPath, $offset, $limit);\r\n\r\n// Show files one by one\r\nforeach ($files as $file) {\r\n    echo $file;\r\n}\r\n\r\n// Show the Pagination\r\necho $pagination-\u003erender();\r\n// Show the per page\r\necho $pagination-\u003eperPageForm();\r\n```\r\n\r\n\r\n## Instance Options\r\n\r\n```php\r\n\u003c?php\r\n\r\nuse DamianPaginationPhp\\Pagination;\r\n\r\n// To change the number of elements displayed per page:\r\n$pagination = new Pagination(['pp' =\u003e 50]);\r\n// Is 15 by default\r\n\r\n// To change number of links alongside the current page:\r\n$pagination = new Pagination(['number_links' =\u003e 10]);\r\n// Is 5 by default\r\n\r\n// To change the choice to select potentially generate with perPageForm():\r\n$pagination = new Pagination(['options_select' =\u003e [5, 10, 50, 100, 500, 'all']]);\r\n// The value of 'options_select' must be an array.\r\n// Only integers and 'all' are permitted.\r\n// Options are [15, 30, 50, 100, 200, 300] by default.\r\n\r\n// To change the CSS style of the pagination (to another CSS class as default):\r\n$pagination = new Pagination(['css_class_p' =\u003e 'name-css-class-of-pagination']);\r\n// The CSS class name is by default \"pagination\".\r\n\r\n// To change the CSS style of the pagination active (to another CSS class as default):\r\n$pagination = new Pagination(['css_class_link_active' =\u003e 'name-css-class-of-pagination']);\r\n// The active CSS class name is by default \"active\".\r\n\r\n// To change the CSS style of a per page (select) (to another id as default):\r\n$pagination = new Pagination(['css_id_pp' =\u003e 'name-css-id-of-per-page-form']);\r\n// The CSS ID name is by default \"per-page-form\".\r\n\r\n// To use Bootstrap CSS:\r\n$pagination = new Pagination(['css_class_p' =\u003e 'pagination']);\r\n// The CSS class name is by default \"block-pagination\"\r\n// We must put \"pagination\"\r\n```\r\n\r\n\r\n## Language Configuration\r\n\r\nYou can change the default language, which is English ('en') by default.\r\n\r\nSupported languages: `cn`, `de`, `ee`, `en`, `es`, `fr`, `it`, `jp`, `pt`, `ru`.\r\n\r\nSet default language:\r\n\r\n```php\r\n\u003c?php\r\n\r\nuse DamianPaginationPhp\\Config\\Config;\r\n\r\n// Change the language to French ('fr').\r\n// Note: It's in English ('en') by default.\r\nConfig::set([\"lang\" =\u003e \"fr\"]);\r\n```\r\n\r\n\r\n## Support\r\n\r\nIf you discover a **bug** or a **security vulnerability**, please send a message to Stephen. Thank you.\r\n\r\nAll bugs and all security vulnerabilities will be promptly addressed.\r\n\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for more details.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs-damian%2Fdamian-pagination-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fs-damian%2Fdamian-pagination-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs-damian%2Fdamian-pagination-php/lists"}