Final Class Yiisoft\Yii\DataView\Pagination\PaginationContext
| Inheritance | Yiisoft\ |
|---|
Context class for pagination widgets that provides URL generation and configuration.
Public Properties
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| createUrl() | Creates a URL for the given page token. | Yiisoft\ |
| translate() | Translate a message using the pagination translation category. | Yiisoft\ |
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\ |
Property Details
Method Details
| public mixed __construct ( string $nextUrlPattern, string $previousUrlPattern, string $firstPageUrl, boolean $accessibility = false, \ | ||
| $nextUrlPattern | string |
URL pattern for next page links. Must contain {@see \ |
| $previousUrlPattern | string |
URL pattern for previous page links. Must contain {@see \ |
| $firstPageUrl | string |
URL used on the first page. |
| $accessibility | boolean |
Whether pagination widgets should add accessibility attributes |
| $translator | \ |
Translator used for pagination messages. When |
| $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);
}
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 ( \ | ||
| $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 a message using the pagination translation category.
| public string translate ( string|\ | ||
| $id | string|\ |
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);
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.