Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
LincolnBruce committed Apr 24, 2018
1 parent 8ffb6d8 commit 263afa4
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 103 deletions.
170 changes: 80 additions & 90 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 29 additions & 12 deletions src/Utils/Page.php → src/Utils/PageUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,40 @@
* @author chenqionghe
* @package libs\Utils
*/
class Page
class PageUtil
{
private $page = 1;
private $total = 1;
private $pageSize = 10;
private $gets = [];
/**
* 当前页码
* @var int
*/
public $page = 1;
/**
* 总条数
* @var int
*/
public $total = 1;
/**
* 每页显示条数
* @var int
*/
public $pageSize = 10;
/**
* url的get参数集
* @var array
*/
public $gets = [];

/**
* Page constructor.
* @param $totalPage int 总条数
* @param int $pageSize 每页显示条数
* @param int $page 当前页码
* @param array $gets url携带get参数数组
* @return self
*/
public function __construct($totalPage, $pageSize = 10, $page = 1, $gets = [])
public static function create($totalPage, $pageSize = 10, $page = 1, $gets = [])
{
$p = new PageUtil();
if ($pageSize < 1) {
$pageSize = 1;
}
Expand All @@ -36,10 +54,11 @@ public function __construct($totalPage, $pageSize = 10, $page = 1, $gets = [])
$page = $total;
}

$this->page = $page;
$this->gets = $gets;
$this->total = $total;
$this->pageSize = $pageSize;
$p->page = $page;
$p->gets = $gets;
$p->total = $total;
$p->pageSize = $pageSize;
return $p;
}

/**
Expand Down Expand Up @@ -220,6 +239,4 @@ private static function getLimit($pageSize)
{
return $pageSize < 1 ? -1 : $pageSize;
}


}
2 changes: 1 addition & 1 deletion test/TestPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
*/
require __DIR__ . '/../src/autoload.php';

$page = new \libs\Utils\Page(1, 10, 10, ['uid' => 3]);
$page = \libs\Utils\PageUtil::create(1, 10, 10, ['uid' => 3]);
echo $page->getPagination('/index');

0 comments on commit 263afa4

Please sign in to comment.