# LinkPager

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

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [widgets](/docs/api/yii/widgets/index.md) › LinkPager

| class | `yii\widgets\LinkPager` |
| --- | --- |
| Extends | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) » [`yii\base\Component`](/docs/api/yii/base/component/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\ViewContextInterface`](/docs/api/yii/base/viewcontextinterface/index.md), [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/widgets/LinkPager.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/widgets/LinkPager.php#L43) |

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

LinkPager works with a [`Pagination`](/docs/api/yii/data/pagination/index.md) 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`](/docs/api/yii/widgets/linkpager/index.md#property-options) and [`$linkContainerOptions`](/docs/api/yii/widgets/linkpager/index.md#property-linkContainerOptions). For example, to opt back into Bootstrap pagination
styles:

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

For more details and usage information on LinkPager, see the [guide article on pagination](/docs/guide/output-pagination/index.md).

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-activePageCssClass"></span>`$activePageCssClass` | `string` | The CSS class for the active (currently selected) page button. Default: `'active'`. | `LinkPager` |
| <span id="property-autoIdPrefix"></span>[`$autoIdPrefix`](/docs/api/yii/base/widget/index.md#property-autoIdPrefix) static | `string` | The prefix to the automatically generated widget IDs. Default: `'w'`. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="property-behaviors"></span>[`$behaviors`](/docs/api/yii/base/component/index.md#property-behaviors) read-only | `array<`[`yii\base\Behavior`](/docs/api/yii/base/behavior/index.md)`<static>>` | List of behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="property-disableCurrentPageButton"></span>`$disableCurrentPageButton` | `bool` | Whether to render current page button as disabled. Default: `false`. Available since 2.0.12. | `LinkPager` |
| [`$disabledListItemSubTagOptions`](#property-disabledListItemSubTagOptions) | `array` | The options for the disabled tag to be generated inside the disabled list element. Default: `[]`. Available since 2.0.11. | `LinkPager` |
| <span id="property-disabledPageCssClass"></span>`$disabledPageCssClass` | `string` | The CSS class for the disabled page buttons. Default: `'disabled'`. | `LinkPager` |
| <span id="property-firstPageCssClass"></span>`$firstPageCssClass` | `string` | The CSS class for the "first" page button. Default: `'first'`. | `LinkPager` |
| [`$firstPageLabel`](#property-firstPageLabel) | `string\|bool` | The text label for the "first" page button. Default: `false`. | `LinkPager` |
| <span id="property-hideOnSinglePage"></span>`$hideOnSinglePage` | `bool` | Hide widget when only one page exist. Default: `true`. | `LinkPager` |
| <span id="property-id"></span>[`$id`](/docs/api/yii/base/widget/index.md#property-id) | `string` | Id of the widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="property-lastPageCssClass"></span>`$lastPageCssClass` | `string` | The CSS class for the "last" page button. Default: `'last'`. | `LinkPager` |
| [`$lastPageLabel`](#property-lastPageLabel) | `string\|bool` | The text label for the "last" page button. Default: `false`. | `LinkPager` |
| <span id="property-linkContainerOptions"></span>`$linkContainerOptions` | `array` | HTML attributes which will be applied to all link containers Default: `[]`. Available since 2.0.13. | `LinkPager` |
| <span id="property-linkOptions"></span>`$linkOptions` | `array` | HTML attributes for the link in a pager container tag. Default: `[]`. | `LinkPager` |
| [`$maxButtonCount`](#property-maxButtonCount) | `int` | Maximum number of page buttons that can be displayed. Default: `10`. | `LinkPager` |
| <span id="property-nextPageCssClass"></span>`$nextPageCssClass` | `string` | The CSS class for the "next" page button. Default: `'next'`. | `LinkPager` |
| [`$nextPageLabel`](#property-nextPageLabel) | `string\|bool` | The label for the "next" page button. Default: `'&raquo;'`. | `LinkPager` |
| <span id="property-options"></span>`$options` | `array` | HTML attributes for the pager container tag. Default: `[]`. | `LinkPager` |
| <span id="property-pageCssClass"></span>`$pageCssClass` | `string` | The CSS class for the each page button. Default: `null`. Available since 2.0.7. | `LinkPager` |
| [`$pagination`](#property-pagination) | [`yii\data\Pagination`](/docs/api/yii/data/pagination/index.md) | The pagination object that this pager is associated with. Default: `null`. | `LinkPager` |
| <span id="property-prevPageCssClass"></span>`$prevPageCssClass` | `string` | The CSS class for the "previous" page button. Default: `'prev'`. | `LinkPager` |
| [`$prevPageLabel`](#property-prevPageLabel) | `string\|bool` | The text label for the "previous" page button. Default: `'&laquo;'`. | `LinkPager` |
| [`$registerLinkTags`](#property-registerLinkTags) | `bool` | Whether to register link tags in the HTML header for prev, next, first and last page. Default: `false`. | `LinkPager` |
| <span id="property-view"></span>[`$view`](/docs/api/yii/base/widget/index.md#property-view) | [`yii\web\View`](/docs/api/yii/web/view/index.md) | The view object that can be used to render views or view files. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="property-viewPath"></span>[`$viewPath`](/docs/api/yii/base/widget/index.md#property-viewPath) read-only | `string` | The directory containing the view files for this widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/component/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__clone"></span>[`__clone()`](/docs/api/yii/base/component/index.md#method-__clone) | This method is called after the object is created by cloning an existing one. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/component/index.md#method-__get) | Returns the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/component/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/component/index.md#method-__set) | Sets the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/component/index.md#method-__unset) | Sets a component property to be null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-afterRun"></span>[`afterRun()`](/docs/api/yii/base/widget/index.md#method-afterRun) | This method is invoked right after a widget is executed. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-attachBehavior"></span>[`attachBehavior()`](/docs/api/yii/base/component/index.md#method-attachBehavior) | Attaches a behavior to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehaviors"></span>[`attachBehaviors()`](/docs/api/yii/base/component/index.md#method-attachBehaviors) | Attaches a list of behaviors to the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-beforeRun"></span>[`beforeRun()`](/docs/api/yii/base/widget/index.md#method-beforeRun) | This method is invoked right before the widget is executed. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-begin"></span>[`begin()`](/docs/api/yii/base/widget/index.md#method-begin) static | Begins a widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-behaviors"></span>[`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) | Returns a list of behaviors that this component should behave as. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/component/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/component/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-detachBehavior"></span>[`detachBehavior()`](/docs/api/yii/base/component/index.md#method-detachBehavior) | Detaches a behavior from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-detachBehaviors"></span>[`detachBehaviors()`](/docs/api/yii/base/component/index.md#method-detachBehaviors) | Detaches all behaviors from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-end"></span>[`end()`](/docs/api/yii/base/widget/index.md#method-end) static | Ends a widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-ensureBehaviors"></span>[`ensureBehaviors()`](/docs/api/yii/base/component/index.md#method-ensureBehaviors) | Makes sure that the behaviors declared in [`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) are attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehavior"></span>[`getBehavior()`](/docs/api/yii/base/component/index.md#method-getBehavior) | Returns the named behavior object. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehaviors"></span>[`getBehaviors()`](/docs/api/yii/base/component/index.md#method-getBehaviors) | Returns all behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getId"></span>[`getId()`](/docs/api/yii/base/widget/index.md#method-getId) | Returns the ID of the widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-getView"></span>[`getView()`](/docs/api/yii/base/widget/index.md#method-getView) | Returns the view object that can be used to render views or view files. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-getViewPath"></span>[`getViewPath()`](/docs/api/yii/base/widget/index.md#method-getViewPath) | Returns the directory containing the view files for this widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-hasEventHandlers"></span>[`hasEventHandlers()`](/docs/api/yii/base/component/index.md#method-hasEventHandlers) | Returns a value indicating whether there is any handler attached to the named event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/component/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/component/index.md#method-hasProperty) | Returns a value indicating whether a property is defined for this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`init()`](#method-init) | Initializes the pager. | `LinkPager` |
| <span id="method-off"></span>[`off()`](/docs/api/yii/base/component/index.md#method-off) | Detaches an existing event handler from this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-on"></span>[`on()`](/docs/api/yii/base/component/index.md#method-on) | Attaches an event handler to an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-render"></span>[`render()`](/docs/api/yii/base/widget/index.md#method-render) | Renders a view. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-renderFile"></span>[`renderFile()`](/docs/api/yii/base/widget/index.md#method-renderFile) | Renders a view file. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| [`run()`](#method-run) | Executes the widget. | `LinkPager` |
| <span id="method-setId"></span>[`setId()`](/docs/api/yii/base/widget/index.md#method-setId) | Sets the ID of the widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-setView"></span>[`setView()`](/docs/api/yii/base/widget/index.md#method-setView) | Sets the view object to be used by this widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-trigger"></span>[`trigger()`](/docs/api/yii/base/component/index.md#method-trigger) | Triggers an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-widget"></span>[`widget()`](/docs/api/yii/base/widget/index.md#method-widget) static | Creates a widget instance and runs it. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| [`getPageRange()`](#method-getPageRange) protected |  | `LinkPager` |
| [`registerLinkTags()`](#method-registerLinkTags) protected | Registers relational link tags in the html header for prev, next, first and last page. | `LinkPager` |
| [`renderPageButton()`](#method-renderPageButton) protected | Renders a page button. | `LinkPager` |
| [`renderPageButtons()`](#method-renderPageButtons) protected | Renders the page buttons. | `LinkPager` |

## Events

| Event | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="event-EVENT_INIT"></span>[`EVENT_INIT`](/docs/api/yii/base/widget/index.md#event-EVENT_INIT) | [`yii\base\Event`](/docs/api/yii/base/event/index.md) | An event that is triggered when the widget is initialized via [`init()`](/docs/api/yii/base/widget/index.md#method-init). Event name: `'init'`. Available since 2.0.11. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="event-EVENT_BEFORE_RUN"></span>[`EVENT_BEFORE_RUN`](/docs/api/yii/base/widget/index.md#event-EVENT_BEFORE_RUN) | [`yii\base\WidgetEvent`](/docs/api/yii/base/widgetevent/index.md) | An event raised right before executing a widget. Event name: `'beforeRun'`. Available since 2.0.11. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="event-EVENT_AFTER_RUN"></span>[`EVENT_AFTER_RUN`](/docs/api/yii/base/widget/index.md#event-EVENT_AFTER_RUN) | [`yii\base\WidgetEvent`](/docs/api/yii/base/widgetevent/index.md) | An event raised right after executing a widget. Event name: `'afterRun'`. Available since 2.0.11. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |

## Property details

### $disabledListItemSubTagOptions <span id="property-disabledListItemSubTagOptions"></span>

```php
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

### $firstPageLabel <span id="property-firstPageLabel"></span>

```php
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.

### $lastPageLabel <span id="property-lastPageLabel"></span>

```php
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.

### $maxButtonCount <span id="property-maxButtonCount"></span>

```php
public int $maxButtonCount = 10
```

Maximum number of page buttons that can be displayed.

Defaults to 10.

### $nextPageLabel <span id="property-nextPageLabel"></span>

```php
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.

### $pagination <span id="property-pagination"></span>

```php
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.

### $prevPageLabel <span id="property-prevPageLabel"></span>

```php
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.

### $registerLinkTags <span id="property-registerLinkTags"></span>

```php
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.

## Method details

### init() <span id="method-init"></span>

```php
public function init(): mixed
```

Initializes the pager.

**Returns**

`mixed`

### run() <span id="method-run"></span>

```php
public function run(): mixed
```

Executes the widget.

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

**Returns**

`mixed`

### getPageRange() <span id="method-getPageRange"></span>

```php
protected function getPageRange(): array
```

**Returns**

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

### registerLinkTags() <span id="method-registerLinkTags"></span>

```php
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()`](/docs/api/yii/data/pagination/index.md#method-getLinks).

**Returns**

`mixed`

**See also**

- <https://www.w3.org/TR/html401/struct/links.html#h-12.1.2>

### renderPageButton() <span id="method-renderPageButton"></span>

```php
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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$label` | `string` | The text label for the button |
| `$page` | `int` | The page number |
| `$class` | `string` | The CSS class for the page button. |
| `$disabled` | `bool` | Whether this page button is disabled |
| `$active` | `bool` | Whether this page button is active |

**Returns**

`string`: The rendering result

### renderPageButtons() <span id="method-renderPageButtons"></span>

```php
protected function renderPageButtons(): string
```

Renders the page buttons.

**Returns**

`string`: The rendering result