Final Class Yiisoft\Yii\DataView\Pagination\KeysetPagination
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
| Uses Traits | Yiisoft\ |
Widget for rendering {@see KeysetPaginator}.
Public Methods
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| getContext() | Gets the current pagination context. | Yiisoft\ |
Method Details
Adds one or more CSS classes to the existing classes of the "previous"/"next" control.
Multiple classes can be added by passing them as separate arguments. null values are filtered out
automatically.
| public self addLinkClass ( \ | ||
| $class | \ |
One or more CSS class names to add. Pass |
| return | self |
A new instance with the specified CSS classes added to existing ones. |
|---|---|---|
public function addLinkClass(BackedEnum|string|null ...$class): self
{
$new = clone $this;
Html::addCssClass($new->linkAttributes, $class);
return $new;
}
Sets the aria-label of the "next page" link. Pass null to omit it.
The value is applied only when accessibility is enabled and only when aria-label is not already present
in {@see \GridView/ListView, it is translated.
| public self ariaLabelNext ( string|null $label ) | ||
| $label | string|null |
The |
| return | self |
New instance with the specified next link |
|---|---|---|
public function ariaLabelNext(?string $label): self
{
$new = clone $this;
$new->ariaLabelNext = $label;
return $new;
}
Sets the aria-label of the "previous page" link. Pass null to omit it.
The value is applied only when accessibility is enabled and only when aria-label is not already present
in {@see \GridView/ListView, it is translated.
| public self ariaLabelPrevious ( string|null $label ) | ||
| $label | string|null |
The |
| return | self |
New instance with the specified previous link |
|---|---|---|
public function ariaLabelPrevious(?string $label): self
{
$new = clone $this;
$new->ariaLabelPrevious = $label;
return $new;
}
Sets the container element attributes.
| public self containerAttributes ( array $attributes ) | ||
| $attributes | array |
HTML attributes for the container element. |
| return | self |
New instance with the specified container attributes. |
|---|---|---|
public function containerAttributes(array $attributes): self
{
$new = clone $this;
$new->containerAttributes = $attributes;
return $new;
}
Sets the container tag name.
| public self containerTag ( string|null $tag ) | ||
| $tag | string|null |
The tag name for the container element.
Common values: 'nav', 'div'. Use |
| return | self |
New instance with the specified container tag. |
|---|---|---|
| throws | InvalidArgumentException |
If tag name is empty. |
public function containerTag(?string $tag): self
{
if ($tag === '') {
throw new InvalidArgumentException('Tag name cannot be empty.');
}
$new = clone $this;
$new->containerTag = $tag;
return $new;
}
Defined in:
Yiisoft\
Creates a new instance with the specified pagination context.
| public static context ( Yiisoft\ | ||
| $context | Yiisoft\ |
The pagination context to use. |
| return | Yiisoft\ |
New instance with the specified context. |
|---|---|---|
final public function context(PaginationContext $context): static
{
$new = clone $this;
$new->context = $context;
return $new;
}
Creates a new instance with the specified paginator and context.
| public static self create ( \ | ||
| $paginator | \ |
The paginator to use. |
| $nextUrlPattern | string |
URL pattern for next page links. Must contain {@see \ |
| $previousUrlPattern | string |
URL pattern for previous page links. Must contain {@see \ |
| $accessibility | boolean |
Whether to add the |
| $translator | \ |
Translator used for the |
| $translationCategory | string |
Category used with the translator. |
| return | self |
New instance with the specified paginator and context. |
|---|---|---|
public static function create(
KeysetPaginator $paginator,
string $nextUrlPattern,
string $previousUrlPattern,
bool $accessibility = false,
?TranslatorInterface $translator = null,
string $translationCategory = BaseListView::DEFAULT_TRANSLATION_CATEGORY,
): self {
return self::widget()
->paginator($paginator)
->context(
new PaginationContext(
$nextUrlPattern,
$previousUrlPattern,
'',
$accessibility,
$translator,
$translationCategory,
),
);
}
Sets the CSS class for disabled item elements.
| public self disabledItemClass ( string|null $class ) | ||
| $class | string|null |
The CSS class for disabled items. |
| return | self |
New instance with the specified disabled item class. |
|---|---|---|
public function disabledItemClass(?string $class): self
{
$new = clone $this;
$new->disabledItemClass = $class;
return $new;
}
Sets HTML attributes for a disabled "previous"/"next" control, layered on top of {@see linkAttributes()}.
| public self disabledLinkAttributes ( array $attributes ) | ||
| $attributes | array |
HTML attributes for the |
| return | self |
New instance with the specified disabled link attributes. |
|---|---|---|
public function disabledLinkAttributes(array $attributes): self
{
$new = clone $this;
$new->disabledLinkAttributes = $attributes;
return $new;
}
Sets the CSS class for a disabled "previous"/"next" control.
A disabled control ("previous" on the first page, "next" on the last page) is rendered as a span element.
| public self disabledLinkClass ( string|null $class ) | ||
| $class | string|null |
The CSS class for the |
| return | self |
New instance with the specified disabled link class. |
|---|---|---|
public function disabledLinkClass(?string $class): self
{
$new = clone $this;
$new->disabledLinkAttributes['class'] = [];
Html::addCssClass($new->disabledLinkAttributes, $class);
return $new;
}
Defined in:
Yiisoft\
Gets the current pagination context.
| protected Yiisoft\ | ||
| return | Yiisoft\ |
The current pagination context. |
|---|---|---|
| throws | LogicException |
If the context has not been set. |
final protected function getContext(): PaginationContext
{
if ($this->context === null) {
throw new LogicException('Context is not set.');
}
return $this->context;
}
Sets the item element attributes.
| public self itemAttributes ( array $attributes ) | ||
| $attributes | array |
HTML attributes for the item elements. |
| return | self |
New instance with the specified item attributes. |
|---|---|---|
public function itemAttributes(array $attributes): self
{
$new = clone $this;
$new->itemAttributes = $attributes;
return $new;
}
Sets the item tag name that wraps the "previous"/"next" control.
| public self itemTag ( string|null $tag ) | ||
| $tag | string|null |
The tag name for the item elements.
Common values: 'li', 'div'. Use |
| return | self |
New instance with the specified item tag. |
|---|---|---|
| throws | InvalidArgumentException |
if tag name is empty. |
public function itemTag(?string $tag): self
{
if ($tag === '') {
throw new InvalidArgumentException('Tag name cannot be empty.');
}
$new = clone $this;
$new->itemTag = $tag;
return $new;
}
Sets the label for the next page link.
| public self labelNext ( string|\ | ||
| $label | string|\ |
The label for the next page link. |
| return | self |
New instance with the specified next label. |
|---|---|---|
public function labelNext(string|Stringable $label): self
{
$new = clone $this;
$new->labelNext = $label;
return $new;
}
Sets the label for the previous page link.
| public self labelPrevious ( string|\ | ||
| $label | string|\ |
The label for the previous page link. |
| return | self |
New instance with the specified previous label. |
|---|---|---|
public function labelPrevious(string|Stringable $label): self
{
$new = clone $this;
$new->labelPrevious = $label;
return $new;
}
Sets the link attributes.
| public self linkAttributes ( array $attributes ) | ||
| $attributes | array |
HTML attributes for the "previous"/"next" control. |
| return | self |
New instance with the specified link attributes. |
|---|---|---|
public function linkAttributes(array $attributes): self
{
$new = clone $this;
$new->linkAttributes = $attributes;
return $new;
}
Set new link classes.
The classes are applied to the "previous"/"next" control — the a element, or the span element that
replaces it when the control is disabled.
Multiple classes can be set by passing them as separate arguments. null values are filtered out
automatically.
| public self linkClass ( \ | ||
| $class | \ |
One or more CSS class names to use. Pass |
public function linkClass(BackedEnum|string|null ...$class): self
{
$new = clone $this;
$new->linkAttributes['class'] = [];
Html::addCssClass($new->linkAttributes, $class);
return $new;
}
Sets the list element attributes.
| public self listAttributes ( array $attributes ) | ||
| $attributes | array |
HTML attributes for the list element. |
| return | self |
New instance with the specified list attributes. |
|---|---|---|
public function listAttributes(array $attributes): self
{
$new = clone $this;
$new->listAttributes = $attributes;
return $new;
}
Sets the list tag name.
| public self listTag ( string|null $tag ) | ||
| $tag | string|null |
The tag name for the list element.
Common values: 'ul', 'div'. Use |
| return | self |
New instance with the specified list tag. |
|---|---|---|
| throws | InvalidArgumentException |
if tag name is empty. |
public function listTag(?string $tag): self
{
if ($tag === '') {
throw new InvalidArgumentException('Tag name cannot be empty.');
}
$new = clone $this;
$new->listTag = $tag;
return $new;
}
Creates a new instance with the specified paginator.
| public static paginator ( \ | ||
| $paginator | \ |
The paginator to use. |
| return | Yiisoft\ |
New instance with the specified paginator. |
|---|---|---|
| throws | Yiisoft\ |
If paginator is not a {@see \ |
public function paginator(PaginatorInterface $paginator): static
{
/** @psalm-suppress DocblockTypeContradiction, NoValue */
if (!$paginator instanceof KeysetPaginator) {
throw new PaginatorNotSupportedException($paginator);
}
$new = clone $this;
$new->paginator = $paginator;
return $new;
}
Renders the pagination controls.
| public string render ( ) | ||
| return | string |
The rendered HTML pagination controls. |
|---|---|---|
| throws | Yiisoft\ |
If paginator is not set. |
public function render(): string
{
if (!$this->showOnSinglePage && !$this->getPaginator()->isPaginationRequired()) {
return '';
}
$result = '';
$context = $this->getContext();
if ($this->containerTag !== null) {
$containerAttributes = $this->containerAttributes;
if (
$context->accessibility
&& $this->ariaLabelNav !== null
&& !array_key_exists('aria-label', $containerAttributes)
) {
$containerAttributes['aria-label'] = $context->translate($this->ariaLabelNav);
}
$result .= Html::openTag($this->containerTag, $containerAttributes) . "\n" ;
}
if ($this->listTag !== null) {
$result .= Html::openTag($this->listTag, $this->listAttributes) . "\n" ;
}
$paginator = $this->getPaginator();
$previousToken = $paginator->getPreviousToken();
$nextToken = $paginator->getNextToken();
$result .= $this->renderItem(
$this->labelPrevious,
$previousToken === null ? null : $context->createUrl($previousToken),
$this->ariaLabelPrevious,
)
. "\n"
. $this->renderItem(
$this->labelNext,
$nextToken === null ? null : $context->createUrl($nextToken),
$this->ariaLabelNext,
);
if ($this->listTag !== null) {
$result .= "\n" . Html::closeTag($this->listTag);
}
if ($this->containerTag !== null) {
$result .= "\n" . Html::closeTag($this->containerTag);
}
return $result;
}
| public self showOnSinglePage ( boolean $show = true ) | ||
| $show | boolean | |
public function showOnSinglePage(bool $show = true): self
{
$new = clone $this;
$new->showOnSinglePage = $show;
return $new;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.