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.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$activePageCssClass | string | The CSS class for the active (currently selected) page button. Default: 'active'. | LinkPager |
$autoIdPrefix static | string | The prefix to the automatically generated widget IDs. Default: 'w'. | yii\ |
$behaviors read-only | array<yii\<static>> | List of behaviors attached to this component. | yii\ |
$disableCurrentPageButton | bool | Whether to render current page button as disabled. Default: false. Available since 2.0.12. | LinkPager |
$disabledListItemSubTagOptions | array | The options for the disabled tag to be generated inside the disabled list element. Default: []. Available since 2.0.11. | LinkPager |
$disabledPageCssClass | string | The CSS class for the disabled page buttons. Default: 'disabled'. | LinkPager |
$firstPageCssClass | string | The CSS class for the “first” page button. Default: 'first'. | LinkPager |
$firstPageLabel | string| | The text label for the “first” page button. Default: false. | LinkPager |
$hideOnSinglePage | bool | Hide widget when only one page exist. Default: true. | LinkPager |
$id | string | Id of the widget. | yii\ |
$lastPageCssClass | string | The CSS class for the “last” page button. Default: 'last'. | LinkPager |
$lastPageLabel | string| | The text label for the “last” page button. Default: false. | LinkPager |
$linkContainerOptions | array | HTML attributes which will be applied to all link containers Default: []. Available since 2.0.13. | LinkPager |
$linkOptions | array | HTML attributes for the link in a pager container tag. Default: []. | LinkPager |
$maxButtonCount | int | Maximum number of page buttons that can be displayed. Default: 10. | LinkPager |
$nextPageCssClass | string | The CSS class for the “next” page button. Default: 'next'. | LinkPager |
$nextPageLabel | string| | The label for the “next” page button. Default: '»'. | LinkPager |
$options | array | HTML attributes for the pager container tag. Default: []. | LinkPager |
$pageCssClass | string | The CSS class for the each page button. Default: null. Available since 2.0.7. | LinkPager |
$pagination | yii\ | The pagination object that this pager is associated with. Default: null. | LinkPager |
$prevPageCssClass | string | The CSS class for the “previous” page button. Default: 'prev'. | LinkPager |
$prevPageLabel | string| | The text label for the “previous” page button. Default: '«'. | LinkPager |
$registerLinkTags | bool | Whether to register link tags in the HTML header for prev, next, first and last page. Default: false. | LinkPager |
$view | yii\ | The view object that can be used to render views or view files. | yii\ |
$viewPath read-only | string | The directory containing the view files for this widget. | yii\ |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__clone() | This method is called after the object is created by cloning an existing one. | yii\ |
__get() | Returns the value of a component property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets the value of a component property. | yii\ |
__unset() | Sets a component property to be null. | yii\ |
afterRun() | This method is invoked right after a widget is executed. | yii\ |
attachBehavior() | Attaches a behavior to this component. | yii\ |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\ |
beforeRun() | This method is invoked right before the widget is executed. | yii\ |
begin() static | Begins a widget. | yii\ |
behaviors() | Returns a list of behaviors that this component should behave as. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
detachBehavior() | Detaches a behavior from the component. | yii\ |
detachBehaviors() | Detaches all behaviors from the component. | yii\ |
end() static | Ends a widget. | yii\ |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\ |
getBehavior() | Returns the named behavior object. | yii\ |
getBehaviors() | Returns all behaviors attached to this component. | yii\ |
getId() | Returns the ID of the widget. | yii\ |
getView() | Returns the view object that can be used to render views or view files. | yii\ |
getViewPath() | Returns the directory containing the view files for this widget. | yii\ |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\ |
hasMethod() | Returns a value indicating whether a method is defined. | yii\ |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\ |
init() | Initializes the pager. | LinkPager |
off() | Detaches an existing event handler from this component. | yii\ |
on() | Attaches an event handler to an event. | yii\ |
render() | Renders a view. | yii\ |
renderFile() | Renders a view file. | yii\ |
run() | Executes the widget. | LinkPager |
setId() | Sets the ID of the widget. | yii\ |
setView() | Sets the view object to be used by this widget. | yii\ |
trigger() | Triggers an event. | yii\ |
widget() static | Creates a widget instance and runs it. | yii\ |
getPageRange() protected | LinkPager | |
registerLinkTags() protected | Registers relational link tags in the html header for prev, next, first and last page. | LinkPager |
renderPageButton() protected | Renders a page button. | LinkPager |
renderPageButtons() protected | Renders the page buttons. | LinkPager |
Events
Section titled “Events”| Event | Type | Description | Defined by |
|---|---|---|---|
EVENT_INIT | yii\ | An event that is triggered when the widget is initialized via init(). Event name: 'init'. Available since 2.0.11. | yii\ |
EVENT_BEFORE_RUN | yii\ | An event raised right before executing a widget. Event name: 'beforeRun'. Available since 2.0.11. | yii\ |
EVENT_AFTER_RUN | yii\ | An event raised right after executing a widget. Event name: 'afterRun'. Available since 2.0.11. | yii\ |
Property details
Section titled “Property details”$disabledListItemSubTagOptions
Section titled “$disabledListItemSubTagOptions ”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
Section titled “$firstPageLabel ”public string|bool $firstPageLabel = falseThe 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
Section titled “$lastPageLabel ”public string|bool $lastPageLabel = falseThe 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
Section titled “$maxButtonCount ”public int $maxButtonCount = 10Maximum number of page buttons that can be displayed.
Defaults to 10.
$nextPageLabel
Section titled “$nextPageLabel ”public string|bool $nextPageLabel = '»'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
Section titled “$pagination ”public yii\data\Pagination $pagination = nullThe pagination object that this pager is associated with.
You must set this property in order to make LinkPager work.
$prevPageLabel
Section titled “$prevPageLabel ”public string|bool $prevPageLabel = '«'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
Section titled “$registerLinkTags ”public bool $registerLinkTags = falseWhether 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
Section titled “Method details”run()
Section titled “run() ”public function run(): mixedExecutes the widget.
This overrides the parent implementation by displaying the generated page buttons.
Returns
mixed
getPageRange()
Section titled “getPageRange() ”protected function getPageRange(): arrayReturns
array: The begin and end pages that need to be displayed.
registerLinkTags()
Section titled “registerLinkTags() ”protected function registerLinkTags(): mixedRegisters relational link tags in the html header for prev, next, first and last page.
These links are generated using Pagination::getLinks().
renderPageButton()
Section titled “renderPageButton() ”protected function renderPageButton(string $label, int $page, string $class, bool $disabled, bool $active): stringRenders 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()
Section titled “renderPageButtons() ”protected function renderPageButtons(): stringRenders the page buttons.
Returns
string: The rendering result