* @date 2015-12-24 */ class LinkPager extends YiiLinkPager { public $nextPageLabel = '下一页'; public $prevPageLabel = '上一页'; public $firstPageLabel = '首页'; public $lastPageLabel = '末页'; public $showSummary = true; public $showJumpPage = true; /** * Executes the widget. * This overrides the parent implementation by displaying the generated page buttons. */ public function run() { if ($this->registerLinkTags) { $this->registerLinkTags(); } $summary = $this->renderSummary(); // $perPage = $this->renderPerPage(); $perPage = ''; $button = $this->renderButtonBar(); $output = $perPage . $button; $output = $this->showSummary ? $summary . $output : $output; echo $output; } /** * @return string */ protected function renderSummary() { $totalCount = $this->pagination->totalCount; if ($totalCount == 0) { return ''; } $pageCount = $this->pagination->getPageCount(); $begin = $this->pagination->getPage() * $this->pagination->pageSize + 1; $end = $begin + $this->pagination->pageSize - 1; if ($totalCount < $this->pagination->pageSize) { $end = $totalCount; } $output = "
$begin - $end条,共$pageCount页,共$totalCount条数据
"; return $output; } /** * @return string */ protected function renderButtonBar() { $buttons = $this->renderPageButtons(); if (true == $this->showJumpPage && !empty($buttons)) { $time = time(); $pid = 'p-'.$time.'-'.mt_rand(1000,9999); $tplURL = $this->pagination->createUrl(0); $tplURL = str_replace('page=1','page=',$tplURL); $buttons = '
'. '
'. '跳转
'. $buttons . '
'; } //window.location.href= this.getAttribute('data-href') return $buttons; } /** * @return string */ protected function renderPerPage() { $totalCount = $this->pagination->totalCount; if ($totalCount == 0) { return ''; } $request = Yii::$app->getRequest(); $params = $request->getQueryParams(); $params[0] = Yii::$app->controller->getRoute(); $urlManager = Yii::$app->getUrlManager(); $params['pageSize'] = 20; $page20 = ($request->get('pageSize') == 20) ? '20' : '20'; $params['pageSize'] = 50; $page50 = ($request->get('pageSize') == 50) ? '50' : '50'; $params['pageSize'] = 100; $page100 = ($request->get('pageSize') == 100) ? '100' : '100'; $output = '
每页: ' . $page20 .$page50 . $page100 . '
'; return $output; } }