LinkPager works with a [[Pagination]] object which specifies the total number
of pages and the current page number.
Note that LinkPager only generates the necessary HTML markups. In order for it
to look like a real pager, you should provide some CSS styles for it.
With the default configuration, LinkPager should look good using Twitter Bootstrap CSS framework.
For more details and usage information on LinkPager, see the guide article on pagination.
private function getPager($pages) { if (self::$_pageLinkPagerOn) { return LinkPager::widget(['pagination' => $pages]); } else { return ['defaultPageSize' => $pages->defaultPageSize, 'forcePageParam' => $pages->forcePageParam, 'limit' => $pages->limit, 'links' => $pages->links, 'offset' => $pages->offset, 'page' => $pages->page, 'pageCount' => $pages->pageCount, 'pageParam' => $pages->pageParam, 'pageSize' => $pages->pageSize, 'pageSizeLimit' => $pages->pageSizeLimit, 'pageSizeParam' => $pages->pageSizeParam, 'params' => $pages->params, 'route' => $pages->route, 'totalCount' => $pages->totalCount, 'urlManager' => $pages->urlManager, 'validatePage' => $pages->validatePage]; } }
public function run() { if ($this->pagination->getPageCount() <= 1) { return; } parent::run(); }
/** * * @return type * @throws base\ErrorException */ public function run() { if (!$this->_filterModel) { throw new base\ErrorException('There is no search model'); } $request = Yii::$app->request; if ($request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; } $data = strtolower($this->requestType) === 'post' && $request->isPost ? $_POST : $_GET; $this->_filterModel->load($this->directPopulating ? $data : [$this->_filterModel->formName() => $data]); $this->_filterModel->search(); if ($this->_filterModel->hasErrors()) { if ($request->isAjax) { return is_callable($this->_validationFailedCallback) ? call_user_func($this->_validationFailedCallback, $this->_filterModel) : ['error' => current($this->_filterModel->getErrors())]; } if (empty($data)) { $this->_filterModel->clearErrors(); } } if (!($dataProvider = $this->_filterModel->getDataProvider())) { throw new base\ErrorException('DataProvider not initialized'); } if ($request->isAjax) { return ['list' => $this->_filterModel->buildModels(), 'pagination' => $this->paginationAsHTML ? LinkPager::widget(['pagination' => $dataProvider->getPagination()]) : $dataProvider->getPagination()]; } return $this->controller->render($this->view ?: $this->id, ['filterModel' => $this->_filterModel, 'dataProvider' => $dataProvider, 'requestType' => $this->requestType, 'directPopulating' => $this->directPopulating]); }
public function init() { parent::init(); $this->prevPageLabel = '上一页'; $this->nextPageLabel = '下一页'; }
/** * @inheritdoc */ public function init() { parent::init(); $this->pluginOptions = ArrayHelper::merge(['wrapper' => '.list-view', 'pagination' => '.pagination', 'next' => '.pagination .next a:first', 'bufferPx' => 40, 'pjax' => ['container' => '#scrollPagerPjaxContainer']], $this->pluginOptions); ScrollPagerAsset::register($this->view); $pluginOptions = Json::encode($this->pluginOptions); $this->view->registerJs("\$('{$this->itemsContainer}').scrollPager({$pluginOptions});"); }
/** * Initializes the pager. */ public function init() { $this->nextPageLabel = Yii::t('app', 'Next') . ' »'; $this->prevPageLabel = '« ' . Yii::t('app', 'Prev.'); $this->firstPageLabel = Yii::t('app', 'First'); $this->lastPageLabel = Yii::t('app', 'Last'); parent::init(); }
/** * Initializes the pager. */ public function init() { $this->nextPageLabel = Module::t('Next') . ' »'; $this->prevPageLabel = '« ' . Module::t('Prev.'); $this->firstPageLabel = Module::t('First'); $this->lastPageLabel = Module::t('Last'); parent::init(); }
public function init() { $this->activePageCssClass = $this->activeCssClass; $this->disabledPageCssClass = $this->disabledCssClass; $this->prevPageCssClass = $this->prevCssClass; $this->nextPageCssClass = $this->nextCssClass; $this->options = ['class' => 'pagination']; $this->linkOptions = ['class' => 'paginate_button']; parent::init(); // TODO: Change the autogenerated stub }
/** * Executes the widget. * * This overrides the parent implementation by initializing jQuery IAS and displaying the generated page buttons. * * @throws \yii\base\InvalidConfigException * @return mixed */ public function run() { // Initialize jQuery IAS plugin $pluginSettings = ['container' => $this->overflowContainer, 'ias' => ['container' => $this->container, 'item' => $this->item, 'pagination' => "{$this->container} .pagination", 'next' => '.next a', 'delay' => $this->delay, 'negativeMargin' => $this->negativeMargin]]; // Register IAS extensions $pluginSettings['extensions'] = $this->registerExtensions([['name' => self::EXTENSION_PAGING], ['name' => self::EXTENSION_SPINNER, 'options' => !empty($this->spinnerSrc) ? ['html' => $this->spinnerTemplate, 'src' => $this->spinnerSrc] : ['html' => $this->spinnerTemplate]], ['name' => self::EXTENSION_TRIGGER, 'options' => ['text' => $this->triggerText, 'html' => $this->triggerTemplate, 'offset' => $this->triggerOffset]], ['name' => self::EXTENSION_NONE_LEFT, 'options' => ['text' => $this->noneLeftText, 'html' => $this->noneLeftTemplate]], ['name' => self::EXTENSION_HISTORY, 'options' => ['prev' => $this->historyPrev], 'depends' => [self::EXTENSION_TRIGGER, self::EXTENSION_PAGING]]]); // Register event handlers $pluginSettings['events'] = $this->registerEventHandlers(['scroll' => [], 'load' => [], 'loaded' => [], 'render' => [], 'rendered' => [], 'noneLeft' => [], 'next' => [], 'ready' => [], 'pageChange' => [self::EXTENSION_PAGING]]); // Render pagination links return LinkPager::widget(['pagination' => $this->pagination, 'options' => ['class' => 'pagination hidden', 'role' => 'iasContainer', 'data-ias' => json_encode($pluginSettings)]]); }
public function init() { parent::init(); $this->options = ['class' => 'dataTables_paginate paging_full_numbers']; $this->linkOptions = ['class' => 'paginate_button']; $this->activePageCssClass = 'paginate_active'; $this->disabledPageCssClass = 'paginate_button_disabled'; $this->firstPageLabel = '首页'; $this->prevPageLabel = '上一页'; $this->nextPageLabel = '下一页'; $this->lastPageLabel = '尾页'; }
public function init() { parent::init(); if ($this->pageSizeMargin) { Html::addCssStyle($this->pageSizeOptions, $this->pageSizeMargin); } if ($this->customPageWidth) { Html::addCssStyle($this->customPageOptions, 'width:' . $this->customPageWidth . 'px;'); } if ($this->customPageMargin) { Html::addCssStyle($this->customPageOptions, $this->customPageMargin); } }
public function actionUploadDict() { $sougouDir = Yii::$app->params['sougouDictDir']; $dictFiles = array(); if (file_exists($sougouDir)) { if (is_writable($sougouDir)) { $oDir = dir($sougouDir); while (($file = $oDir->read()) !== false) { if (strcasecmp($file, '.') != 0 && strcasecmp($file, '..') != 0) { $filename = $sougouDir . '/' . $file; if (is_dir($filename)) { $subDir = dir($filename); while (($subFile = $subDir->read()) !== false) { if (strcasecmp($subFile, '.') != 0 && strcasecmp($subFile, '..') != 0) { $dictFiles[$file][] = $subFile; } } } } } } else { exit('目录不可写'); } } $count = count($dictFiles); $page = isset($_REQUEST['page']) ? $_REQUEST['page'] ? $_REQUEST['page'] : 1 : 1; $pageSize = 10; $start = ($page - 1) * $pageSize; $pager = new \yii\data\Pagination(array('defaultPageSize' => $pageSize, 'totalCount' => $count)); if ($page > $pager->getPageCount() && $page != 1) { exit('超过最大页数'); } $data = array(); if ($count) { $sArr = array_slice($dictFiles, $start, $pageSize, true); foreach ($sArr as $time => $value) { if (!empty($value)) { foreach ($value as $key => $val) { if (preg_match('/\\.scel/', $val)) { $file = $sougouDir . '/' . $time . '/' . $val; $data[$time][$key] = array('filename' => mb_convert_encoding($val, 'UTF-8', 'GBK,GB2312'), 'filesize' => \app\common\XUtils::file_size_format(filesize($file)), 'filetype' => filetype($file), 'filetime' => date('Y-m-d H:i:s', filemtime($file))); } } } } } if (Yii::$app->request->isPost) { exit(json_encode(array('data' => $data, 'pager' => \yii\widgets\LinkPager::widget(['pagination' => $pager, 'prevPageLabel' => '上一页', 'nextPageLabel' => '下一页'])))); } return $this->render('uploaddict', array('data' => $data, 'pager' => $pager)); }
/** * @inheritdoc * @see \yii\widgets\LinkPager::init() */ public function init() { parent::init(); if ($this->itemsOrderDesc) { $firstPageLabel = $this->firstPageLabel; $lastPageLabel = $this->lastPageLabel; $this->firstPageLabel = $lastPageLabel; $this->lastPageLabel = $firstPageLabel; $nextPageLabel = $this->nextPageLabel; $prevPageLabel = $this->prevPageLabel; $this->nextPageLabel = $prevPageLabel; $this->prevPageLabel = $nextPageLabel; } }
public function init() { parent::init(); $this->_page_param = $this->pagination->pageParam; $this->_page_size_param = $this->pagination->pageSizeParam; $currentPageSize = $this->pagination->getPageSize(); // Push current pageSize to $this->pageSizeList, // unique to avoid duplicating if (!in_array($currentPageSize, $this->pageSizeList)) { array_unshift($this->pageSizeList, $currentPageSize); $this->pageSizeList = array_unique($this->pageSizeList); // Sort sort($this->pageSizeList, SORT_NUMERIC); } }
public function testFirstLastPageLabels() { $pagination = new Pagination(); $pagination->setPage(5); $pagination->totalCount = 500; $pagination->route = 'test'; $output = LinkPager::widget(['pagination' => $pagination, 'firstPageLabel' => true, 'lastPageLabel' => true]); static::assertContains('<li class="first"><a href="/?r=test&page=1" data-page="0">1</a></li>', $output); static::assertContains('<li class="last"><a href="/?r=test&page=25" data-page="24">25</a></li>', $output); $output = LinkPager::widget(['pagination' => $pagination, 'firstPageLabel' => 'First', 'lastPageLabel' => 'Last']); static::assertContains('<li class="first"><a href="/?r=test&page=1" data-page="0">First</a></li>', $output); static::assertContains('<li class="last"><a href="/?r=test&page=25" data-page="24">Last</a></li>', $output); $output = LinkPager::widget(['pagination' => $pagination, 'firstPageLabel' => false, 'lastPageLabel' => false]); static::assertNotContains('<li class="first">', $output); static::assertNotContains('<li class="last">', $output); }
/** * 用户列表 * @return [type] [description] */ public function actionIndex() { $model = new \app\models\WAdmin(); $currentPage = $this->_getPost('page') ? $this->_getPost('page') : 1; $pageSize = $this->_getPost('pageSize') ? $this->_getPost('pageSize') : 10; $where = 1; if ($this->_getPost('searchName')) { $where = $this->buildQuery(['username' => $this->_getPost('searchName')], 'and'); } $data = $model->getAdminList(($currentPage - 1) * $pageSize, $pageSize, $where); foreach ($data['data'] as $key => $value) { $data['data'][$key]['last_login_time'] = date('Y-m-d H:i:s', $value['last_login_time']); } $pager = new \yii\data\Pagination(array('defaultPageSize' => $pageSize, 'totalCount' => $data['count']['n'])); if (\Yii::$app->request->isGet) { return $this->render('index', array('datalist' => $data['data'], 'pager' => $pager)); } else { exit(json_encode(array('datalist' => $data['data'], 'pager' => \yii\widgets\LinkPager::widget(['pagination' => $pager, 'prevPageLabel' => '上一页', 'nextPageLabel' => '下一页'])))); } }
public function run() { if (!$this->_filterModel) { throw new base\ErrorException('Не указана модель поиска'); } $request = Yii::$app->request; if ($request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; } // Проставляем данные $data = strtolower($this->requestType) === 'post' && $request->isPost ? $_POST : $_GET; $this->_filterModel->load($this->directPopulating ? $data : [$this->_filterModel->formName() => $data]); // Производим выборку в модели поиска $this->_filterModel->search(); // Если при поиске произошла ошибка валидации if ($this->_filterModel->hasErrors()) { /** * В зависимости от запроса решаем что делать, * если ajax то сбрасываем ошибку, иначе если входящих данных нет, очищаем ошибки */ if ($request->isAjax) { return is_callable($this->_validationFailedCallback) ? call_user_func($this->_validationFailedCallback, $this->_filterModel) : ['error' => current($this->_filterModel->getErrors())]; } if (empty($data)) { $this->_filterModel->clearErrors(); } } if (!($dataProvider = $this->_filterModel->getDataProvider())) { throw new base\ErrorException('Не проинициализирован DataProvider'); } if ($request->isAjax) { // Возвращаем корректно сформированную коллекцию объектов return ['list' => $this->_filterModel->buildModels(), 'pagination' => $this->paginationAsHTML ? LinkPager::widget(['pagination' => $dataProvider->getPagination()]) : $dataProvider->getPagination()]; } return $this->controller->render($this->view ?: $this->id, ['filterModel' => $this->_filterModel, 'dataProvider' => $dataProvider, 'requestType' => $this->requestType, 'directPopulating' => $this->directPopulating]); }
/** * Renders the pager. * @return string the rendering result */ public function renderPager() { $pagination = $this->dataProvider->getPagination(); if ($pagination === false || $this->dataProvider->getCount() <= 0) { return ''; } /* @var $class LinkPager */ $pager = $this->pager; $class = ArrayHelper::remove($pager, 'class', LinkPager::className()); $pager['pagination'] = $pagination; $pager['view'] = $this->getView(); return $class::widget($pager); }
?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create Post', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php /* echo ListView::widget([ 'dataProvider' => $dataProvider, 'itemView' => '_post', ]);*/ //die(print_r($posts)); foreach ($posts as $post) { echo $this->render('_post', ['model' => $post]); } ?> <div> <?php echo LinkPager::widget(['pagination' => $pages]); ?> </div> </div>
<?php foreach ($countries as $k => $v) { echo '<tr>'; echo '<td>' . ($k + 1) . '</td>'; echo '<td>' . Tool::echoEncodeString($v->employName) . '</td>'; echo '<td>' . GlobalArray::$employStatusArr[Tool::echoEncodeString($v->status, 0)] . '</td>'; echo '<td>' . Tool::echoEncodeString($v->count) . '</td>'; echo '<td>' . GlobalArray::$employGroupArr[Tool::echoEncodeString($v->group, '0')] . '</td>'; echo '<td>' . GlobalArray::$employTypeArr[Tool::echoEncodeString($v->type, '0')] . '</td>'; echo ' <td>' . Tool::echoEncodeString($v->money) . '</td>'; echo '<td>' . Tool::echoEncodeString($v->address) . '</td>'; echo '<td><a href="' . Yii::$app->urlManager->createUrl([\common\widgets\Variable::$editEmploy_url, 'id' => Tool::echoEncodeString($v->id)]) . '">编辑</a><a onclick="deleteEmploy(this,' . Tool::echoEncodeString($v->id) . ')">删除</a></td>'; echo '</tr>'; } ?> </table> </div> </div> <!-- <embed src="http://player.youku.com/player.php/Type/Folder/Fid/16980025/Ob/1/Pt/0/sid/XMzQ3Njg5MTAw/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="always" allowFullScreen="true" mode="transparent" type="application/x-shockwave-flash"></embed>--> <?php echo LinkPager::widget(['pagination' => $pagination, 'nextPageLabel' => '下一页', 'prevPageLabel' => '上一页', 'firstPageLabel' => '首页', 'lastPageLabel' => '末页']); ?> </div> </div> </div>
<br> 地点:<?php echo $item->place; ?> <br> 活动概要:<?php echo $item->summary; ?> <span class="badge pull-right">提交时间:<?php echo $item->created_at; ?> </span> </p> </a> <?php } ?> </div> <?php echo LinkPager::widget(['pagination' => $noreply_page]); ?> </div> </div> </div>
<?php /** * @var $dataProvider \yii\data\ActiveDataProvider */ use yii\widgets\LinkPager; ?> <div class="row"> <?php echo $dataProvider->pagination->totalCount > $dataProvider->pagination->pageSize ? LinkPager::widget(['pagination' => $dataProvider->pagination]) : ''; ?> </div>
if (!$pagination && strlen($postsHtml) > 0) { $postsUrl = Url::toRoute(['/$basePath']); if (Yii::$app->cmgCore->multiSite && Yii::$app->cmgCore->subDirectory) { $siteName = Yii::$app->cmgCore->getSiteName(); $postsUrl = Url::toRoute(["/{$siteName}/{$basePath}"]); } ?> <div class="post-all"> <a href="<?php echo $postsUrl; ?> ">View All</a> </div> <?php } else { if (strlen($postsHtml) <= 0) { ?> <p>No posts found.</p> <?php } } ?> <?php if ($pagination && strlen($postsHtml) > 0 && isset($dataProvider)) { $pagination = $dataProvider->getPagination(); $pageInfo = CodeGenUtil::getPaginationDetail($dataProvider); $pageLinks = LinkPager::widget(['pagination' => $pagination]); $pagination = "<div class='wrap-pagination clearfix'>\n\t\t\t\t\t\t<div class='info'>{$pageInfo}</div>\n\t\t\t\t\t\t{$pageLinks}\n\t\t\t\t </div>"; echo $pagination; }
<div class="error-actions"> <a href="<?php echo \yii\helpers\Url::to(['/site/index']); ?> " class="btn btn-lg btn-orange tooltip-test mainserarchsubmit"><span class="glyphicon glyphicon-home"></span> Take Me Home </a> </div> </div> </div> </div> </div> <?php } ?> <!-- Paging--> <div class="mt30 clearfix"> <?php echo \yii\widgets\LinkPager::widget(['pagination' => $dataProvider->pagination]); ?> ?> </div> </div> </div> </div> </div> </div> </div>
<p class="entry-summary"> <?php echo $post->post_excerpt; ?> ... </p> <footer class="footer-meta"> <h3> <?php $tags = $post->getTerms()->innerJoinWith(['taxonomy'])->andWhere(['taxonomy_slug' => 'tag'])->all(); foreach ($tags as $tag) { echo Html::a($tag->term_name, $tag->url, ['class' => 'badge']) . "\n"; } ?> </h3> </footer> </div> </div> </article> <?php } ?> <nav id="archive-pagination"> <?php echo LinkPager::widget(['pagination' => $pages, 'activePageCssClass' => 'active', 'disabledPageCssClass' => 'disabled', 'options' => ['class' => 'pagination']]); ?> </nav> <?php } ?> </div>
<td><?php echo $model->stateName; ?> </td> <td><?php echo $model->replyUser['nickname']; ?> </td> <td><?php echo $model->replyContent; ?> </td> <td><?php echo $model->replyDate; ?> </td> </tr> <?php } ?> </tbody> </table> <nav class="pull-right pagination_footer"> <?php echo \yii\widgets\LinkPager::widget(['pagination' => $pages]); ?> </nav> <div class="clearfix"></div> </div> </div>
<div class="tour-info fl"> <img src="<?php echo $this->theme->getUrl('assets/img/calendar_icon_grey.png'); ?> " alt=""> <span class="font-style-2 color-dark-2"><?php echo date('d.m.y', strtotime($model->dateCreate)); ?> </span> </div> </div> <br> <a href="<?php echo $model->oneUrl; ?> " class="c-button small bg-dr-blue-2 hv-dr-blue-2-o"><span>Подробнее</span></a> </div> </div> </div> <?php } ?> </div> <div class="c_pagination clearfix"> <?php echo LinkPager::widget(['pagination' => $pagination, 'options' => ['class' => 'cp_content color-3']]); ?> </div> </div> </div>
public function api_pages() { return $this->_adp ? LinkPager::widget(['pagination' => $this->_adp->pagination]) : ''; }
<?php use yii\widgets\LinkPager; echo date("Y-m-d", $firstDay); ?> <?php foreach ($materials as $material) { ?> <?php echo $material->title; ?> </br> <?php } ?> <?php echo LinkPager::widget(['pagination' => $pages, 'registerLinkTags' => true]);
$url['p'] = $gotopage; } echo '<div class="item-commentcount">', Html::a($topic['comment_count'], $url, ['class' => 'count_livid']), '</div>'; } echo Html::a(Html::encode($topic['node']['name']), ['topic/node', 'name' => $topic['node']['ename']], ['class' => 'node']), ' • <strong>', Html::a(Html::encode($topic['author']['username']), ['user/view', 'username' => Html::encode($topic['author']['username'])]), '</strong>', ' • ', Yii::$app->formatter->asRelativeTime($topic['replied_at']); if ($topic['comment_count'] > 0) { echo '<span class="item-lastreply"> • 最后回复者 ', Html::a(Html::encode($topic['lastReply']['username']), ['user/view', 'username' => Html::encode($topic['lastReply']['username'])]), '</span>'; } echo '</div> </div>'; echo '</div>'; } ?> <div class="item-pagination"> <?php echo LinkPager::widget(['pagination' => $pages, 'maxButtonCount' => 5]); ?> </div> </div> </div> <!-- sf-left end --> <!-- sf-right start --> <div class="col-md-4 sf-right"> <?php echo $this->render('@app/views/common/_right'); ?> </div> <!-- sf-right end -->