{"id":15691706,"url":"https://github.com/gargron/paginator","last_synced_at":"2025-05-08T01:14:32.091Z","repository":{"id":2809143,"uuid":"3810277","full_name":"Gargron/Paginator","owner":"Gargron","description":"Minimal PHP paginator class. Generates pagination navigation based on total items number and offset.","archived":false,"fork":false,"pushed_at":"2013-01-27T12:36:19.000Z","size":103,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-08T01:14:25.534Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Gargron.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-03-23T16:33:41.000Z","updated_at":"2019-01-03T09:35:05.000Z","dependencies_parsed_at":"2022-09-10T15:11:11.000Z","dependency_job_id":null,"html_url":"https://github.com/Gargron/Paginator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gargron%2FPaginator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gargron%2FPaginator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gargron%2FPaginator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gargron%2FPaginator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gargron","download_url":"https://codeload.github.com/Gargron/Paginator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252978783,"owners_count":21834917,"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":[],"created_at":"2024-10-03T18:23:30.854Z","updated_at":"2025-05-08T01:14:32.060Z","avatar_url":"https://github.com/Gargron.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Paginator\n\nVery small PHP class to generate pagination links.\n\n## Usage\n\nIn your controller/route:\n\n    \u003c?php\n    $offset      = intval($_GET['offset']);\n    $per_page    = 20;\n    $total_items = 60;\n    $query_items = array('something' =\u003e 'to_persist_on_paginator_links');\n    \n    $paginator   = new Gargron\\Paginator('/example/url', $offset, $per_page, $total_items, $query_items);\n    ?\u003e\n\nIn your view or wherever you want the links rendered:\n\n    \u003c?php echo $paginator-\u003elinks(); ?\u003e\n\n## Alternative usage\n\nIf you don't want to count the total number of results (as it may be an expensive and unneccessary query),\nthe paginator can render simple next/previous links instead, but guessing if the respective link is needed.\n\n    \u003c?php\n    $offset      = intval($_GET['offset']);\n    $per_page    = 20; # We want to display only 20 items per page\n    $results     = DB::query(\"SELECT * FROM test LIMIT ?, 21\", array($offset)); # But we fetch maximally 21\n    $fetched     = count($results); # We count how many we *actually* fetched\n    $results     = array_slice($results, 0, 20); # We strip away the items that we don't want to display\n    $query_items = array('something' =\u003e 'to_persist_on_paginator_links');\n    \n    $paginator   = new Gargron\\Paginator('/example/url', $offset, $per_page, null, $query_items);\n    $paginator-\u003ecurrentFetched = $fetched;\n\nIn your view or where you want the links rendered:\n\n    \u003c?php echo $paginator-\u003elinks(); ?\u003e\n\nThe logic behind this is very simple. If the number of actually fetched items is greater than the number\nof items we want to display per page, it means there *is* a next page available. As for the previous link,\nif the offset is greater than 0, there must be a previous page.\n\n## Localization (and dependency)\n\nThe class uses the function `__()` when rendering the links. If you are not using a framework\nthat already defines that function, you can define it as follows:\n\n    function __($key)\n    {\n        $translations = array(\n            'pagination.first'    =\u003e 'First',\n            'pagination.previous' =\u003e 'Previous',\n            'pagination.next'     =\u003e 'Next',\n            'pagination.last'     =\u003e 'Last',\n        );\n        \n        return array_key_exists($key, $translations) ? $translations[$key] : $key;\n    }\n\nI understand that adding a makedo function like that may not seem optimal, but if you are ever going\nto localize your application, you'll be happy your Paginator class doesn't need any monkeypatching!\n\n## Example of generated mark-up\n\n    \u003cdiv class=\"pagination pagination-centered\"\u003e\n    \t\u003cul\u003e\n    \t\t\u003cli\u003e\u003ca href=\"/?offset=0\"\u003ePrevious\u003c/a\u003e\u003c/li\u003e\n    \t\t\u003cli\u003e\u003ca href=\"/?offset=0\"\u003e1\u003c/a\u003e\u003c/li\u003e\n    \t\t\u003cli class=\"active\"\u003e\u003ca href=\"/?offset=20\"\u003e2\u003c/a\u003e\u003c/li\u003e\n    \t\t\u003cli\u003e\u003ca href=\"/?offset=40\"\u003e3\u003c/a\u003e\u003c/li\u003e\n    \t\t\u003cli\u003e\u003ca href=\"/?offset=60\"\u003eNext\u003c/a\u003e\u003c/li\u003e\n    \t\u003c/ul\u003e\n    \u003c/div\u003e\u003c!-- Bootstrap-ready :D --\u003e\n\n### License\n\nPaginator is released under the [MIT license](http://www.opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgargron%2Fpaginator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgargron%2Fpaginator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgargron%2Fpaginator/lists"}