{"id":15308188,"url":"https://github.com/yidas/php-pagination","last_synced_at":"2025-04-15T00:54:37.360Z","repository":{"id":44342811,"uuid":"147849108","full_name":"yidas/php-pagination","owner":"yidas","description":"PHP Paginator with Pager Widget (pure PHP, CI, Yii, Laravel support)","archived":false,"fork":false,"pushed_at":"2023-05-29T02:43:44.000Z","size":18,"stargazers_count":25,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T00:54:25.285Z","etag":null,"topics":["data-pagination","linkpager","pagination-widget","paginator","php","php-pagination"],"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/yidas.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}},"created_at":"2018-09-07T16:31:34.000Z","updated_at":"2024-07-05T21:40:53.000Z","dependencies_parsed_at":"2024-06-20T22:09:13.677Z","dependency_job_id":null,"html_url":"https://github.com/yidas/php-pagination","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"d6b95bbab65e75b69517f755df3e23f93b4e0e78"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yidas%2Fphp-pagination","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yidas%2Fphp-pagination/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yidas%2Fphp-pagination/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yidas%2Fphp-pagination/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yidas","download_url":"https://codeload.github.com/yidas/php-pagination/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248986279,"owners_count":21194025,"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":["data-pagination","linkpager","pagination-widget","paginator","php","php-pagination"],"created_at":"2024-10-01T08:14:25.752Z","updated_at":"2025-04-15T00:54:37.342Z","avatar_url":"https://github.com/yidas.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"***php*** Pagination\n===============\n\nPHP Paginator with Pager Widget (pure PHP, CI, Yii, Laravel support)\n\n[![Latest Stable Version](https://poser.pugx.org/yidas/pagination/v/stable?format=flat-square)](https://packagist.org/packages/yidas/pagination)\n[![License](https://poser.pugx.org/yidas/pagination/license?format=flat-square)](https://packagist.org/packages/yidas/pagination)\n\nFeatures\n--------\n\n- *Compatible with pure PHP, Codeigniter, Yii \u0026 Laravel*\n\n- ***SOLID principle** with Yii 2 pattern like*\n\n- ***Pagination Widget** (View Block) included* \n\n---\n\nOUTLINE\n-------\n\n- [Demonstration](#demonstration)\n- [Requirements](#requirements)\n    - [PDO with pure PHP](#pdo-with-pure-php)\n    - [Codeiginter 3 Framework](#codeiginter-3-framework)\n    - [Widget Render](#widget-render)\n- [Installation](#installation)\n    - [Codeigniter 3](#codeigniter-3)\n- [Configuration](#configuration)\n    - [Inheritance](#inheritance)\n- [Usage](#usage)\n    - [Widget](#widget)\n        - [Customized View](#customized-view)\n        - [Inheritance](#inheritance-1)\n    - [Build URL](#build-url)\n- [API Documentation](#api-documentation)\n- [Examples](#examples)\n    - [PDO with pure PHP](#pdo-with-pure-php-1)\n    - [Codeiginter 3 Framework](#codeiginter-3-framework-1)\n- [References](#references)\n\n---\n\nDEMONSTRATION\n-------------\n\n### PDO with pure PHP\n\n```php\n// Get count of data set first\n$sql = \"SELECT count(*) FROM `table`\"; \n$count = $conn-\u003equery($sql)-\u003efetchColumn(); \n\n// Initialize a Data Pagination with previous count number\n$pagination = new \\yidas\\data\\Pagination([\n    'totalCount' =\u003e $count,\n]);\n\n// Get range data for the current page\n$sql = \"SELECT * FROM `table` LIMIT {$pagination-\u003eoffset}, {$pagination-\u003elimit}\"; \n$sth = $conn-\u003eprepare($sql);\n$sth-\u003eexecute();\n$data = $sth-\u003efetchAll();\n```\n\n### Codeiginter 3 Framework\n\n```php\n$query = $this-\u003edb-\u003ewhere('type', 'C');\n\n// Clone same query for get total count\n$countQuery = clone $query;\n\n// Get total count from cloned query\n// Or you could use count_all_results('', false) to keep query instead of using `clone`\n$count = $countQuery-\u003ecount_all_results();\n\n// Initialize a Data Pagination with previous count number\n$pagination = new \\yidas\\data\\Pagination([\n    'totalCount' =\u003e $count,\n]);\n\n// Get range data for the current page\n$records = $query\n    -\u003eoffset($pagination-\u003eoffset)\n    -\u003elimit($pagination-\u003elimit)\n    -\u003eget()-\u003eresult_array();\n```\n\n### Widget Render\n\n```php\n\u003cdiv\u003e\n\u003c?=\\yidas\\widgets\\Pagination::widget([\n    'pagination' =\u003e $pagination\n])?\u003e\n\u003c/div\u003e\n```\n\n\u003cimg src=\"https://raw.githubusercontent.com/yidas/php-pagination/master/img/widget.png\" width=\"300px\" /\u003e\n\n\u003e `$pagination` is the object of `yidas\\data\\Pagination`.\n\n---\n\nREQUIREMENTS\n------------\nThis library requires the following:\n\n- PHP 5.4.0+\n\n---\n\nINSTALLATION\n------------\n\nRun Composer in your project:\n\n    composer require yidas/pagination\n\nThen initialize it at the bootstrap of application such as config file:\n\n```php\nrequire __DIR__ . '/vendor/autoload.php';\n```\n\n### Codeigniter 3 \n\nRun Composer in your Codeigniter project under the folder `\\application`:\n\n    composer require yidas/pagination\n    \nCheck Codeigniter `application/config/config.php`:\n\n```php\n$config['composer_autoload'] = TRUE;\n```\n    \n\u003e You could customize the vendor path into `$config['composer_autoload']`\n\n---\n\nCONFIGURATION\n-------------\n\nThe simple config and usage could refer to [Demonstration](#demonstration).\n\nWhen you are dealing with pagination, you could new `yidas\\data\\Pagination` with configuration to get pager information for data query. For example:\n\n```php\n// Get total rows from your query\n$count = $query-\u003ecount();\n// Initialize a Data Pagination\n$pagination = new \\yidas\\data\\Pagination([\n    'totalCount' =\u003e $count,\n    'pergpage' =\u003e 10,\n]);\n// ...use $pagination offset/limit info for your query\n```\n\nFor more parameters, you could refer to [API Documentation](#api-documentation).\n\n### Inheritance\n\nYou could build your application data Pagination with styles Inherited from `yidas\\data\\Pagination`. For example:\n\n```php\nnamespace yidas\\data;\n\nuse yidas\\data\\Pagination as BasePagination;\n\nclass Pagination extends BasePagination\n{\n    // Name of the parameter storing the current page index\n    public $pageParam = 'page';\n    \n    // The number of items per page\n    public $perPage = 10;\n    \n    // Name of the parameter storing the page size\n    // false to turn off per-page input by client\n    public $perPageParam = false;\n}\n```\n\n---\n\nUSAGE\n-----\n\nWhen there are too much data to be displayed on a single page, a common strategy is to display them in multiple pages and on each page only display a small portion of the data. This strategy is known as *pagination*.\n\nThis library uses a `yidas\\data\\Pagination` object to represent the information about a pagination scheme. In particular,\n\n- `total count` specifies the total number of data items. Note that this is usually much more than the number of data items needed to display on a single page.\n- `page size` specifies how many data items each page contains. The default value is 20.\n- `current page` gives the current page number (not zero-based). The default value is 1, meaning the first page.\n\nWith a fully specified `yidas\\data\\Pagination object`, you can retrieve and display data partially. For example, if you are fetching data from a database, you can specify the `OFFSET` and `LIMIT` clause of the DB query with the corresponding values provided by the pagination. Below is an example:\n\n```php\n/**\n * Yii 2 Framework sample code\n */\nuse yidas\\data\\Pagination;\n\n// build a DB query to get all articles with status = 1\n$query = Article::find()-\u003ewhere(['status' =\u003e 1]);\n\n// get the total number of articles (but do not fetch the article data yet)\n$count = $query-\u003ecount();\n\n// create a pagination object with the total count\n$pagination = new Pagination(['totalCount' =\u003e $count]);\n\n// limit the query using the pagination and retrieve the articles\n$articles = $query-\u003eoffset($pagination-\u003eoffset)\n    -\u003elimit($pagination-\u003elimit)\n    -\u003eall();\n```\n\n### Widget\n\nTo facilitate building the UI element that supports pagination, This library provides the `yii\\widgets\\Pagination` widget that displays a list of page buttons upon which users can click to indicate which page of data should be displayed. The widget takes a pagination object so that it knows what is the current page and how many page buttons should be displayed. For example,\n\n```php\nuse yidas\\widgets\\Pagination;\n\necho  Pagination::widget([\n    'pagination' =\u003e $pagination\n]);\n```\n\u003e `$pagination` is a `yidas\\data\\Pagination` object for data provider.\n\n#### Customized View\n\nThe default widget view is for Bootstrap(`bootstrap`), you could choose a template view for your Pagination Widget:\n\n```php\necho  \\yidas\\widgets\\Pagination::widget([\n    'pagination' =\u003e $pagination,\n    'view' =\u003e 'simple',\n]);\n```\n\n|Template |Description|\n|:--------|:----------|\n|bootstrap|Default view, supports for Bootstrap 3 and 4|\n|simple   |Simple `\u003cdiv\u003e` with `\u003ca\u003e` tags for pure HTML/CSS style|\n\n\nYou can also use your customized view for Pagination widget:\n\n```php\necho  \\yidas\\widgets\\Pagination::widget([\n    'pagination' =\u003e $pagination,\n    'view' =\u003e __DIR__ . '/../widgets/pagination_view.php',\n]);\n```\n\n#### Inheritance\n\nYou could build your application Pagination Widget with styles Inherited from `yidas\\widgets\\Pagination`. For example:\n\n```php\n\u003c?php\n\nnamespace app\\widgets;\n\nuse yidas\\widgets\\Pagination as BaseWidget;\n\n/**\n * Pagination Widget\n */\nclass Pagination extends BaseWidget\n{\n    // Set the Widget pager is center align or not   \n    public $alignCenter = false;\n    \n    // Maximum number of page buttons that can be displayed   \n    public $buttonCount = 7;\n\n    // The text label for the \"first\" page button\n    public $firstPageLabel = '\u003ci class=\"fa fa-step-backward\" aria-hidden=\"true\"\u003e\u003c/i\u003e';\n\n    // The text label for the \"last\" page button\n    public $lastPageLabel = '\u003ci class=\"fa fa-step-forward\" aria-hidden=\"true\"\u003e\u003c/i\u003e';\n    \n    // The text label for the \"next\" page button\n    public $nextPageLabel = '\u003ci class=\"fa fa-caret-right\" aria-hidden=\"true\"\u003e\u003c/i\u003e';\n    \n    // The text label for the \"previous\" page button\n    public $prevPageLabel = '\u003ci class=\"fa fa-caret-left\" aria-hidden=\"true\"\u003e\u003c/i\u003e';\n    \n    // \u003cul\u003e class. For example, 'pagination-sm' for Bootstrap small size.\n    public $ulCssClass = '';\n}\n```\n\n\n### Build URL\n\nIf you want to build UI element manually, you may use `yidas\\data\\Pagination::createUrl()` to create URLs that would lead to different pages. The method requires a page parameter and will create a properly formatted URL containing the page parameter. For example:\n\n```php\n// ex. https://yoursite.com/list/\n// displays: https://yoursite.com/list/?page=100\necho $pagination-\u003ecreateUrl(100);\n\n// ex. https://yoursite.com/list/?sort=desc\u0026type=a\n// displays: https://yoursite.com/list/?sort=desc\u0026type=a\u0026page=101\necho $pagination-\u003ecreateUrl(101);\n```\n\u003e The formatted URL pattern is `//{current-host-uri}{parameters-with-pagination}`\n\nYou could also build a `per-page` setting URL for changing `per-page` when `perPageParam` is set:\n\n```php\n// ex. https://yoursite.com/list/\n// displays: https://yoursite.com/list/?page=1\u0026per-page=50\necho $pagination-\u003ecreateUrl(1, 50);\n```\n\n---\n\nEXAMPLES\n--------\n\n### PDO with Pure PHP\n\n```php\n$conn = new PDO(\"mysql:host=localhost;dbname=database\", 'username', 'password');\n\n// Get count of data set first\n$sql = \"SELECT count(*) FROM `table`\"; \n$count = $conn-\u003equery($sql)-\u003efetchColumn(); \n\n// Initialize a Data Pagination with previous count number\n$pagination = new \\yidas\\data\\Pagination([\n    'totalCount' =\u003e $count,\n]);\n\n// Get range data for the current page\n$sql = \"SELECT * FROM `table` LIMIT {$pagination-\u003eoffset}, {$pagination-\u003elimit}\"; \n$sth = $conn-\u003eprepare($sql);\n$sth-\u003eexecute();\n$data = $sth-\u003efetchAll();\n\nprint_r($data);\n```\n\nLinkPager display:\n\n```php\necho yidas\\widgets\\Pagination::widget([\n    'pagination' =\u003e $pagination\n]);\n```\n\n### Codeiginter 3 Framework\n\nCodeiginter 3 Framework with [yidas/codeigniter-model](https://github.com/yidas/codeigniter-model):\n\n```php\n$this-\u003eload-\u003emodel('Post_model');\n\n$query = $this-\u003ePost_model-\u003efind()\n    -\u003ewhere('type', 'C');\n    \n// Clone same query for get total count\n$countQuery = clone $query;\n\n// Get total count from cloned query\n// Or you could use count(false) to keep query instead of using `clone`\n$count = $countQuery-\u003ecount();\n\n// Initialize a Data Pagination with previous count number\n$pagination = new \\yidas\\data\\Pagination([\n    'totalCount' =\u003e $count,\n]);\n\n// Get range data for the current page\n$records = $query\n    -\u003eoffset($pagination-\u003eoffset)\n    -\u003elimit($pagination-\u003elimit)\n    -\u003eget()-\u003eresult_array();\n```\n\nLinkPager in view:\n\n```php\n\u003cdiv\u003e\n\u003c?=yidas\\widgets\\Pagination::widget([\n    'pagination' =\u003e $pagination\n])?\u003e\n\u003c/div\u003e\n```\n\n---\n\nAPI DOCUMENTATION\n-----------------\n\n### Data Pagination\n\n|Public Property|Type   |Description   |\n|:--            |:--    |:--           |\n|$limit         |integer|The limit of the data|\n|$offset        |integer|The offset of the data|\n|$page          |integer|The current page number (zero-based). The default value is 1, meaning the first page.|\n|$pageCount     |integer|Number of pages|\n|$pageParam     |string |Name of the parameter storing the current page index, default value is `page`|\n|$perPage       |integer|The number of items per page, default value is 20|\n|$perPageParam  |string |Name of the parameter storing the page size, default value is `per-page`|\n|$perPageLimit  |array  |The per page number limits. The first array element stands for the minimal page size, and the second the maximal page size, default value is `[1, 50]`|\n|$params        |array  |Parameters (name =\u003e value) that should be used to obtain the current page number and to create new pagination URLs|\n|$totalCount    |integer|Total number of items|\n|$validatePage  |boolean|Whether to check if $page is within valid range|\n\n### Widget Pagination\n\n|Public Property|Type   |Description   |\n|:--            |:--    |:--           |\n|$alignCenter   |boolean|Set the Widget pager is center align or not, default value is `true`|\n|$buttonCount   |integer|Maximum number of page buttons that can be displayed, default value is |\n|$pagination|yidas\\data\\Pagination|The data pagination object that this pager is associated with|\n|$firstPageLabel|string |The text label for the \"first\" page button, default value is `First`|\n|$lastPageLabel |string |The text label for the \"last\" page button, default value is `Last`|\n|$nextPageLabel |string |The text label for the \"next\" page button, default value is `Next`|\n|$prevPageLabel |string |The text label for the \"previous\" page button, default value is `Prev`|\n|$firstPageCssClass|string|The CSS class for the \"first\" page button|\n|$lastPageCssClass|string|The CSS class for the \"last\" page button|\n|$nextPageCssClass|string|The CSS class for the \"next\" page button|\n|$prevPageCssClass|string|The CSS class for the \"previous\" page button|\n|$pageCssClass|string   |The CSS class for the each page button, default value is `page-item`|\n|$ulCssClass |string   |The CSS class for the ul element of pagination. For example, 'pagination-sm' for Bootstrap small size.|\n|$linkAttributes|array  |HTML attributes for the link in a pager container tag, default value is ['class' =\u003e 'page-link']|\n|$view          |string |The view name or absolute file path that can be used to render view. ([Template view choices](#customized-view))|\n\n---\n\nREFERENCES\n----------\n\n[Yii 2 PHP Framework - Displaying Data: Pagination](https://www.yiiframework.com/doc/guide/2.0/en/output-pagination)\n\n[Yii 2 PHP Framework - Class yii\\data\\Pagination](https://www.yiiframework.com/doc/api/2.0/yii-data-pagination)\n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyidas%2Fphp-pagination","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyidas%2Fphp-pagination","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyidas%2Fphp-pagination/lists"}