0

Final Class Yiisoft\Yii\DataView\Pagination\PaginationContext

InheritanceYiisoft\Yii\DataView\Pagination\PaginationContext

Context class for pagination widgets that provides URL generation and configuration.

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Yii\DataView\Pagination\PaginationContext
createUrl() Creates a URL for the given page token. Yiisoft\Yii\DataView\Pagination\PaginationContext
translate() Translate a message using the pagination translation category. Yiisoft\Yii\DataView\Pagination\PaginationContext

Constants

Hide inherited constants

Constant Value Description Defined By
URL_PLACEHOLDER 'YII-DATAVIEW-PAGE-PLACEHOLDER' Placeholder used in URL patterns that will be replaced with the actual page token. Yiisoft\Yii\DataView\Pagination\PaginationContext

Property Details

Hide inherited properties

$accessibility public property
public boolean $accessibility = false
$firstPageUrl public property
public string $firstPageUrl = null
$nextUrlPattern public property
public string $nextUrlPattern = null
$previousUrlPattern public property

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string $nextUrlPattern, string $previousUrlPattern, string $firstPageUrl, boolean $accessibility = false, \Yiisoft\Translator\TranslatorInterface|null $translator = null, string $translationCategory = BaseListView::DEFAULT_TRANSLATION_CATEGORY )
$nextUrlPattern string

URL pattern for next page links. Must contain {@see \Yiisoft\Yii\DataView\Pagination\URL_PLACEHOLDER}.

$previousUrlPattern string

URL pattern for previous page links. Must contain {@see \Yiisoft\Yii\DataView\Pagination\URL_PLACEHOLDER}.

$firstPageUrl string

URL used on the first page.

$accessibility boolean

Whether pagination widgets should add accessibility attributes aria-* automatically.

$translator \Yiisoft\Translator\TranslatorInterface|null

Translator used for pagination messages. When null, a default translator is created: it leaves message IDs as is and only substitutes their parameters.

$translationCategory string

Category used with the translator.

                public function __construct(
    public readonly string $nextUrlPattern,
    public readonly string $previousUrlPattern,
    public readonly string $firstPageUrl,
    public readonly bool $accessibility = false,
    ?TranslatorInterface $translator = null,
    private readonly string $translationCategory = BaseListView::DEFAULT_TRANSLATION_CATEGORY,
) {
    $this->translator = $translator ?? DefaultTranslatorFactory::create($translationCategory);
}

            
createUrl() public method

Creates a URL for the given page token.

This method replaces the URL_PLACEHOLDER in either the next or previous URL pattern (depending on the token type) with the URL-encoded token value.

public string createUrl ( \Yiisoft\Data\Paginator\PageToken $pageToken )
$pageToken \Yiisoft\Data\Paginator\PageToken

Token for the page.

return string

The generated URL with the token value properly encoded.

                public function createUrl(PageToken $pageToken): string
{
    return str_replace(
        self::URL_PLACEHOLDER,
        urlencode($pageToken->value),
        $pageToken->isPrevious ? $this->previousUrlPattern : $this->nextUrlPattern,
    );
}

            
translate() public method

Translate a message using the pagination translation category.

public string translate ( string|\Stringable $id, array $parameters = [] )
$id string|\Stringable

Message ID to translate.

$parameters array

Parameters for the message.

return string

Translated message.

                public function translate(string|Stringable $id, array $parameters = []): string
{
    return $this->translator->translate($id, $parameters, $this->translationCategory);
}