Skip to content

build Pagination Library to create better pagination for json response

Notifications You must be signed in to change notification settings

smhnaqvi/php-pagination

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-pagination

simple library to create easily pagination for rest apis json response

install package using composer

composer require smhnaqvi/json-response

OR

clone from github repository

git clone [email protected]:smhnaqvi/php-json-response.git

usage

use Libraries\Pagination\Pagination;

// create Pagination instance
// argument 1 has number of total records and accept integer value
// argument 2 is current page number by default its 1 integer value
// argument 3 is number of how many showing result per page and by default its 10 integer value
$records = 52; 
$currentPage = 6; 
$showPerPage = 3;
$paging = new Pagination($records, $currentPage, $showPerPage);

::paginate

return pagination object

$paginate = $paging->paginate();
$total = $paginate->total;
$current_page = $paginate->current_page;
$all_pages = $paginate->all_pages;
$per_page = $paginate->per_page;
$has_pagination = $paginate->has_pagination;

::toJson

show pagination final result and using exit() to stop php process and json_encode() to encode data to json .

$paging->toJson();

::toArray

return array of pagination object

$pageArr = $paging->toArray();
$total = $pageArr["total"];
$current_page = $pageArr["current_page"];
$all_pages = $pageArr["all_pages"];
$per_page = $pageArr["per_page"];
$has_pagination = $pageArr["has_pagination"];

::getOffset

return calculated offset for pagination

$offset = $paging->getOffset(); // return int value

About

build Pagination Library to create better pagination for json response

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages