Skip to content
PHP Ecosystem
Explore

LinkPager

API reference › yii › widgets › LinkPager

LinkPager displays a list of hyperlinks that lead to different pages of target.

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 CSS styles for it.

LinkPager is CSS-agnostic by default and does not apply any framework-specific classes; supply the classes your CSS framework expects via $options and $linkContainerOptions. For example, to opt back into Bootstrap pagination styles:

echo LinkPager::widget(
[
'pagination' => $pagination,
'options' => ['class' => 'pagination'],
],
);

For more details and usage information on LinkPager, see the guide article on pagination.

PropertyTypeDescriptionDefined by
$activePageCssClassstringThe CSS class for the active (currently selected) page button. Default: 'active'.LinkPager
$autoIdPrefix staticstringThe prefix to the automatically generated widget IDs. Default: 'w'.yii\base\Widget
$behaviors read-onlyarray<yii\base\Behavior<static>>List of behaviors attached to this component.yii\base\Component
$disableCurrentPageButtonboolWhether to render current page button as disabled. Default: false. Available since 2.0.12.LinkPager
$disabledListItemSubTagOptionsarrayThe options for the disabled tag to be generated inside the disabled list element. Default: []. Available since 2.0.11.LinkPager
$disabledPageCssClassstringThe CSS class for the disabled page buttons. Default: 'disabled'.LinkPager
$firstPageCssClassstringThe CSS class for the “first” page button. Default: 'first'.LinkPager
$firstPageLabelstring|boolThe text label for the “first” page button. Default: false.LinkPager
$hideOnSinglePageboolHide widget when only one page exist. Default: true.LinkPager
$idstringId of the widget.yii\base\Widget
$lastPageCssClassstringThe CSS class for the “last” page button. Default: 'last'.LinkPager
$lastPageLabelstring|boolThe text label for the “last” page button. Default: false.LinkPager
$linkContainerOptionsarrayHTML attributes which will be applied to all link containers Default: []. Available since 2.0.13.LinkPager
$linkOptionsarrayHTML attributes for the link in a pager container tag. Default: [].LinkPager
$maxButtonCountintMaximum number of page buttons that can be displayed. Default: 10.LinkPager
$nextPageCssClassstringThe CSS class for the “next” page button. Default: 'next'.LinkPager
$nextPageLabelstring|boolThe label for the “next” page button. Default: '&raquo;'.LinkPager
$optionsarrayHTML attributes for the pager container tag. Default: [].LinkPager
$pageCssClassstringThe CSS class for the each page button. Default: null. Available since 2.0.7.LinkPager
$paginationyii\data\PaginationThe pagination object that this pager is associated with. Default: null.LinkPager
$prevPageCssClassstringThe CSS class for the “previous” page button. Default: 'prev'.LinkPager
$prevPageLabelstring|boolThe text label for the “previous” page button. Default: '&laquo;'.LinkPager
$registerLinkTagsboolWhether to register link tags in the HTML header for prev, next, first and last page. Default: false.LinkPager
$viewyii\web\ViewThe view object that can be used to render views or view files.yii\base\Widget
$viewPath read-onlystringThe directory containing the view files for this widget.yii\base\Widget
MethodDescriptionDefined by
__construct()Constructor.yii\base\BaseObject
__call()Calls the named method which is not a class method.yii\base\Component
__clone()This method is called after the object is created by cloning an existing one.yii\base\Component
__get()Returns the value of a component property.yii\base\Component
__isset()Checks if a property is set, i.e. defined and not null.yii\base\Component
__set()Sets the value of a component property.yii\base\Component
__unset()Sets a component property to be null.yii\base\Component
afterRun()This method is invoked right after a widget is executed.yii\base\Widget
attachBehavior()Attaches a behavior to this component.yii\base\Component
attachBehaviors()Attaches a list of behaviors to the component.yii\base\Component
beforeRun()This method is invoked right before the widget is executed.yii\base\Widget
begin() staticBegins a widget.yii\base\Widget
behaviors()Returns a list of behaviors that this component should behave as.yii\base\Component
canGetProperty()Returns a value indicating whether a property can be read.yii\base\Component
canSetProperty()Returns a value indicating whether a property can be set.yii\base\Component
className() staticReturns the fully qualified name of this class.yii\base\BaseObject
detachBehavior()Detaches a behavior from the component.yii\base\Component
detachBehaviors()Detaches all behaviors from the component.yii\base\Component
end() staticEnds a widget.yii\base\Widget
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.yii\base\Component
getBehavior()Returns the named behavior object.yii\base\Component
getBehaviors()Returns all behaviors attached to this component.yii\base\Component
getId()Returns the ID of the widget.yii\base\Widget
getView()Returns the view object that can be used to render views or view files.yii\base\Widget
getViewPath()Returns the directory containing the view files for this widget.yii\base\Widget
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.yii\base\Component
hasMethod()Returns a value indicating whether a method is defined.yii\base\Component
hasProperty()Returns a value indicating whether a property is defined for this component.yii\base\Component
init()Initializes the pager.LinkPager
off()Detaches an existing event handler from this component.yii\base\Component
on()Attaches an event handler to an event.yii\base\Component
render()Renders a view.yii\base\Widget
renderFile()Renders a view file.yii\base\Widget
run()Executes the widget.LinkPager
setId()Sets the ID of the widget.yii\base\Widget
setView()Sets the view object to be used by this widget.yii\base\Widget
trigger()Triggers an event.yii\base\Component
widget() staticCreates a widget instance and runs it.yii\base\Widget
getPageRange() protectedLinkPager
registerLinkTags() protectedRegisters relational link tags in the html header for prev, next, first and last page.LinkPager
renderPageButton() protectedRenders a page button.LinkPager
renderPageButtons() protectedRenders the page buttons.LinkPager
EventTypeDescriptionDefined by
EVENT_INITyii\base\EventAn event that is triggered when the widget is initialized via init(). Event name: 'init'. Available since 2.0.11.yii\base\Widget
EVENT_BEFORE_RUNyii\base\WidgetEventAn event raised right before executing a widget. Event name: 'beforeRun'. Available since 2.0.11.yii\base\Widget
EVENT_AFTER_RUNyii\base\WidgetEventAn event raised right after executing a widget. Event name: 'afterRun'. Available since 2.0.11.yii\base\Widget
public array $disabledListItemSubTagOptions = []

The options for the disabled tag to be generated inside the disabled list element.

In order to customize the html tag, please use the tag key.

$disabledListItemSubTagOptions = ['tag' => 'div', 'class' => 'disabled-div'];

Since

2.0.11

public string|bool $firstPageLabel = false

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 string|bool $lastPageLabel = false

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 int $maxButtonCount = 10

Maximum number of page buttons that can be displayed.

Defaults to 10.

public string|bool $nextPageLabel = '&raquo;'

The label for the “next” page button.

Note that this will NOT be HTML-encoded. If this property is false, the “next” page button will not be displayed.

public yii\data\Pagination $pagination = null

The pagination object that this pager is associated with.

You must set this property in order to make LinkPager work.

public string|bool $prevPageLabel = '&laquo;'

The text label for the “previous” page button.

Note that this will NOT be HTML-encoded. If this property is false, the “previous” page button will not be displayed.

public bool $registerLinkTags = false

Whether to register link tags in the HTML header for prev, next, first and last page.

Defaults to false to avoid conflicts when multiple pagers are used on one page.

public function init(): mixed

Initializes the pager.

Returns

mixed

public function run(): mixed

Executes the widget.

This overrides the parent implementation by displaying the generated page buttons.

Returns

mixed

protected function getPageRange(): array

Returns

array: The begin and end pages that need to be displayed.

protected function registerLinkTags(): mixed

Registers relational link tags in the html header for prev, next, first and last page.

These links are generated using Pagination::getLinks().

protected function renderPageButton(string $label, int $page, string $class, bool $disabled, bool $active): string

Renders a page button.

You may override this method to customize the generation of page buttons.

Parameters

ParameterTypeDescription
$labelstringThe text label for the button
$pageintThe page number
$classstringThe CSS class for the page button.
$disabledboolWhether this page button is disabled
$activeboolWhether this page button is active

Returns

string: The rendering result

protected function renderPageButtons(): string

Renders the page buttons.

Returns

string: The rendering result