mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-21 00:54:53 +08:00
yii\widgets\LinkPager::$firstPageLabel and yii\widgets\LinkPager::$lastPageLabel now could be set to true in order to use page number as label
This commit is contained in:
@@ -46,6 +46,7 @@ Yii Framework 2 Change Log
|
||||
- Enh: Added `yii\helper\Console::wrapText()` method to wrap indented text by console window width and used it in `yii help` command (cebe)
|
||||
- Enh: Implement batchInsert for oci (nineinchnick)
|
||||
- Enh: Detecting IntegrityException for oci (nineinchnick)
|
||||
- Enh: `yii\widgets\LinkPager::$firstPageLabel` and `yii\widgets\LinkPager::$lastPageLabel` now could be set to true in order to use page number as label (samdark)
|
||||
- Chg #7924: Migrations in history are now ordered by time applied allowing to roll back in reverse order no matter how these were applied (samdark)
|
||||
- Chg: Updated dependency to `cebe/markdown` to version `1.1.x` (cebe)
|
||||
|
||||
|
||||
@@ -83,11 +83,13 @@ class LinkPager extends Widget
|
||||
public $prevPageLabel = '«';
|
||||
/**
|
||||
* @var string|boolean the text label for the "first" page button. Note that this will NOT be HTML-encoded.
|
||||
* If it's specified as true, page number will be used as label.
|
||||
* Default is false that means the "first" page button will not be displayed.
|
||||
*/
|
||||
public $firstPageLabel = false;
|
||||
/**
|
||||
* @var string|boolean the text label for the "last" page button. Note that this will NOT be HTML-encoded.
|
||||
* If it's specified as true, page number will be used as label.
|
||||
* Default is false that means the "last" page button will not be displayed.
|
||||
*/
|
||||
public $lastPageLabel = false;
|
||||
@@ -154,8 +156,9 @@ class LinkPager extends Widget
|
||||
$currentPage = $this->pagination->getPage();
|
||||
|
||||
// first page
|
||||
if ($this->firstPageLabel !== false) {
|
||||
$buttons[] = $this->renderPageButton($this->firstPageLabel, 0, $this->firstPageCssClass, $currentPage <= 0, false);
|
||||
$firstPageLabel = $this->firstPageLabel === true ? '1' : $this->firstPageLabel;
|
||||
if ($firstPageLabel !== false) {
|
||||
$buttons[] = $this->renderPageButton($firstPageLabel, 0, $this->firstPageCssClass, $currentPage <= 0, false);
|
||||
}
|
||||
|
||||
// prev page
|
||||
@@ -181,8 +184,9 @@ class LinkPager extends Widget
|
||||
}
|
||||
|
||||
// last page
|
||||
if ($this->lastPageLabel !== false) {
|
||||
$buttons[] = $this->renderPageButton($this->lastPageLabel, $pageCount - 1, $this->lastPageCssClass, $currentPage >= $pageCount - 1, false);
|
||||
$lastPageLabel = $this->lastPageLabel === true ? $pageCount - 1 : $this->lastPageLabel;
|
||||
if ($lastPageLabel !== false) {
|
||||
$buttons[] = $this->renderPageButton($lastPageLabel, $pageCount - 1, $this->lastPageCssClass, $currentPage >= $pageCount - 1, false);
|
||||
}
|
||||
|
||||
return Html::tag('ul', implode("\n", $buttons), $this->options);
|
||||
|
||||
59
tests/framework/widgets/LinkPagerTest.php
Normal file
59
tests/framework/widgets/LinkPagerTest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace yiiunit\framework\widgets;
|
||||
|
||||
use yii\data\Pagination;
|
||||
use yii\widgets\LinkPager;
|
||||
|
||||
/**
|
||||
* @group widgets
|
||||
*/
|
||||
class LinkPagerTest extends \yiiunit\TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->mockApplication([
|
||||
'components' => [
|
||||
'urlManager' => [
|
||||
'scriptUrl' => '/'
|
||||
]
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
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">24</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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user