{"id":37007168,"url":"https://github.com/salernolabs/pagination","last_synced_at":"2026-01-14T00:46:31.492Z","repository":{"id":57047781,"uuid":"200316444","full_name":"salernolabs/pagination","owner":"salernolabs","description":"A simple library that wraps some pagination stuff and can buildd bootstrap HTML","archived":false,"fork":false,"pushed_at":"2019-08-03T19:25:27.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-23T02:57:26.800Z","etag":null,"topics":["bootstrap","helper","pagination","php"],"latest_commit_sha":null,"homepage":"https://www.salernolabs.com/","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/salernolabs.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}},"created_at":"2019-08-03T01:10:43.000Z","updated_at":"2019-08-03T21:22:54.000Z","dependencies_parsed_at":"2022-08-23T18:50:58.853Z","dependency_job_id":null,"html_url":"https://github.com/salernolabs/pagination","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/salernolabs/pagination","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salernolabs%2Fpagination","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salernolabs%2Fpagination/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salernolabs%2Fpagination/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salernolabs%2Fpagination/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/salernolabs","download_url":"https://codeload.github.com/salernolabs/pagination/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salernolabs%2Fpagination/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["bootstrap","helper","pagination","php"],"created_at":"2026-01-14T00:46:30.868Z","updated_at":"2026-01-14T00:46:31.479Z","avatar_url":"https://github.com/salernolabs.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# salernolabs/pagination\n\n[![Latest Stable Version](https://poser.pugx.org/salernolabs/pagination/v/stable)](https://packagist.org/packages/salernolabs/pagination)\n[![License](https://poser.pugx.org/salernolabs/pagination/license)](https://packagist.org/packages/salernolabs/pagination)\n[![Build Status](https://travis-ci.com/salernolabs/pagination.svg?branch=master)](https://travis-ci.org/salernolabs/pagination)\n\nA simple library that wraps some common pagination stuff and can build bootstrap HTML. Yes I know a billion of these exist, I've been offloading old code into individual tested libraries for organization purposes as I move some sites over to Symfony. I may add more formatters at some point, I've been playing with material ui as well, but its not here yet. PR's welcome.\n\n![Example Pagination Image](docs/images/pagination.png)\n\n## Installation\n\n    composer require salernolabs/pagination\n    \n## How to Use\n\nThe idea is to build a pagination object (base or formatted), input some values, retrieve all the pagination info plus html you want.\n\n### Base Pagination Class\n\nThe constructor takes several optional arguments. They can also be set with set* methods.\n\n    $p = new \\SalernoLabs\\Pagination\\Pagination(\n      $pageNumber,\n      $numberOfItemsPerPage,\n      $totalItems\n    );\n\nGet all the calculated pagination data with `$p-\u003egetPaginationData()`;\n\n### PageData Response Class\n\nThe `-\u003egetPaginationData()` method will return the [PageData](src/PageData.php) response object. The following methods are available on this object:\n\n| Method | Return Type | Info |\n|--------|------|-------|\n| `getPageNumber()` | int | The current page number, unless it exceeds calculated total pages in which case the last page number is returned. |\n| `getTotalItems()` | int | The total number of items, this is what you originally entered |\n| `getItemsPerPage()` | int | The total number of items per page, this is what you originally entered. |\n| `getOffset()` | int | The calculated database row offset value, suitable for queries |\n| `getTotalPages()` | int |  The calculated total number of pages |\n    \n### BootstrapHTML Generator\n\nThe [BootstrapHTML](src/Formatter/BootstrapHTML.php) formatter object extends the base pagination class and provides an extra function for generating HTML suitable for raw output in a template on a site that includes the [Bootstrap](https://getbootstrap.com/) library.\n\n#### `-\u003egenerateOutput($paginationUrl, $pageNumberConstant, $additionalUrlData)`\n\nThis method will generate the output for you using the input parameters to format the urls. If your paginated URLs are of the format `/news/1` for page 1, `/news/2` etc, your first parameter would be `'/news/#'`.\n\nIf your URL format is more like `'/articles/index?pageNumber=44'` you could do `'/articles/index?pageNumber=#'`\n\nIf you need to change the value `#` in the url template, the second parameter can change it.\n\nFinally the third parameter just adds extra stuff to the end of your URLs. \n\n#### Usage Example\n\n    $articleCount = /* query article count */ 500;\n\n    $pagination = new \\SalernoLabs\\Pagination\\Formatter\\BootstrapHTML();\n    $pagination\n        -\u003esetPageNumber(1)\n        -\u003esetNumberOfItemsPerPage(20)\n        -\u003esetTotalItems($articleCount);\n    $page = $pagination-\u003egetPaginationData();\n    \n    // eg. LIMIT $page-\u003egetOffset(), $page-\u003egetItemsPerPage()\n    \n    $paginationHTML = $pagination-\u003egenerateOutput('/news/#', '#');\n\nAt this point you should have the HTML you need to output.\n\n#### Customizing the HTML\n\nThere are some extra methods in formatters to tweak the output of the HTML. They are as follows: \n\n| Method | Default | Info |\n|--------|------|-------|\n| `setNextButton()` | `\u0026rsaquo;` | Sets the text for the \"next\" button. |\n| `setPreviousButton()` | `\u0026lsaquo;` | Sets the text for the \"previous\" button. |\n| `setFirstButton()` | `\u0026laquo;` | Sets the text for the \"first\" button. |\n| `setLastButton()` | `\u0026raquo;` | Sets the text for the \"last\" button. |\n| `setSpace()` | `\u0026nbsp;` | Sets the string to use for spaces. |\n| `setItemStride()` | `5` | Sets the stride, basically controls the number of number buttons. A value of five would show five before the current value and five including and after the current value for a total of 10. |\n\n### Testing\n\nTesting is just PHPunit. Example build with coverage report if you've loaded composer dev dependencies:\n\n    php vendor/phpunit/phpunit/phpunit --coverage-html build/coverage-report\n    \nWe aimed for 100% coverage in version 1.#","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalernolabs%2Fpagination","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsalernolabs%2Fpagination","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalernolabs%2Fpagination/lists"}