BaseListView
API reference › yii › widgets › BaseListView
2 subclasses
BaseListView is a base class for widgets displaying data from data provider such as ListView and GridView.
It provides features like sorting, paging and also filtering the data.
For more details and usage information on BaseListView, see the guide article on data widgets.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$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\ |
$dataProvider | yii\ | The data provider for the view. Default: null. | BaseListView |
$emptyText | string| | The HTML content to be displayed when $dataProvider does not have any data. Default: null. | BaseListView |
$emptyTextOptions | array | The HTML attributes for the emptyText of the list view. Default: ['class' => 'empty']. | BaseListView |
$id | string | Id of the widget. | yii\ |
$layout | string | The layout that determines how different sections of the list view should be organized. Default: "{summary}\. | BaseListView |
$options | array | The HTML attributes for the container tag of the list view. Default: []. | BaseListView |
$pager | array | The configuration for the pager widget. Default: []. | BaseListView |
$showOnEmpty | bool | Whether to show an empty list view if $dataProvider returns no data. Default: false. | BaseListView |
$sorter | array | The configuration for the sorter widget. Default: []. | BaseListView |
$summary | string| | The HTML content to be displayed as the summary of the list view. Default: null. | BaseListView |
$summaryOptions | array | The HTML attributes for the summary of the list view. Default: ['class' => 'summary']. | BaseListView |
$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 view. | BaseListView |
off() | Detaches an existing event handler from this component. | yii\ |
on() | Attaches an event handler to an event. | yii\ |
render() | Renders a view. | yii\ |
renderEmpty() | Renders the HTML content indicating that the list view has no data. | BaseListView |
renderFile() | Renders a view file. | yii\ |
renderItems() abstract | Renders the data models. | BaseListView |
renderPager() | Renders the pager. | BaseListView |
renderSection() | Renders a section of the specified name. | BaseListView |
renderSorter() | Renders the sorter. | BaseListView |
renderSummary() | Renders the summary text. | BaseListView |
run() | Runs the widget. | BaseListView |
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\ |
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”$dataProvider
Section titled “$dataProvider ”public yii\data\DataProviderInterface $dataProvider = nullThe data provider for the view.
This property is required.
$emptyText
Section titled “$emptyText ”public string|false|null $emptyText = nullThe HTML content to be displayed when $dataProvider does not have any data.
When this is set to false no extra HTML content will be generated.
The default value is the text “No results found.” which will be translated to the current application language.
$emptyTextOptions
Section titled “$emptyTextOptions ”public array $emptyTextOptions = ['class' => 'empty']The HTML attributes for the emptyText of the list view.
The “tag” element specifies the tag name of the emptyText element and defaults to “div”.
$layout
Section titled “$layout ”public string $layout = "{summary}\n{items}\n{pager}"The layout that determines how different sections of the list view should be organized.
The following tokens will be replaced with the corresponding section contents:
{summary}: the summary section. SeerenderSummary().{items}: the list items. SeerenderItems().{sorter}: the sorter. SeerenderSorter().{pager}: the pager. SeerenderPager().
$options
Section titled “$options ”public array $options = []The HTML attributes for the container tag of the list view.
The “tag” element specifies the tag name of the container element and defaults to “div”.
$pager
Section titled “$pager ”public array $pager = []The configuration for the pager widget.
By default, LinkPager will be
used to render the pager. You can use a different widget class by configuring the “class” element.
Note that the widget must support the pagination property which will be populated with the
pagination value of the $dataProvider and will overwrite this value.
$showOnEmpty
Section titled “$showOnEmpty ”public bool $showOnEmpty = falseWhether to show an empty list view if $dataProvider returns no data.
The default value is false which displays an element according to the $emptyText
and $emptyTextOptions properties.
$sorter
Section titled “$sorter ”public array $sorter = []The configuration for the sorter widget.
By default, LinkSorter will be
used to render the sorter. You can use a different widget class by configuring the “class” element.
Note that the widget must support the sort property which will be populated with the
sort value of the $dataProvider and will overwrite this value.
$summary
Section titled “$summary ”public string|null $summary = nullThe HTML content to be displayed as the summary of the list view.
If you do not want to show the summary, you may set it with an empty string.
The following tokens will be replaced with the corresponding values:
{begin}: the starting row number (1-based) currently being displayed{end}: the ending row number (1-based) currently being displayed{count}: the number of rows currently being displayed{totalCount}: the total number of rows available{page}: the page number (1-based) current being displayed{pageCount}: the number of pages available
$summaryOptions
Section titled “$summaryOptions ”public array $summaryOptions = ['class' => 'summary']The HTML attributes for the summary of the list view.
The “tag” element specifies the tag name of the summary element and defaults to “div”.
Method details
Section titled “Method details”renderEmpty()
Section titled “renderEmpty() ”public function renderEmpty(): stringRenders the HTML content indicating that the list view has no data.
renderItems()
Section titled “renderItems() ”abstract public function renderItems(): stringRenders the data models.
Returns
string: The rendering result.
renderPager()
Section titled “renderPager() ”public function renderPager(): stringRenders the pager.
Returns
string: The rendering result
renderSection()
Section titled “renderSection() ”public function renderSection(string $name): string|boolRenders a section of the specified name.
If the named section is not supported, false will be returned.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | The section name, e.g., {summary}, {items}. |
Returns
string|bool: The rendering result of the section, or false if the named section is not supported.
renderSorter()
Section titled “renderSorter() ”public function renderSorter(): stringRenders the sorter.
Returns
string: The rendering result
renderSummary()
Section titled “renderSummary() ”public function renderSummary(): mixedRenders the summary text.
Returns
mixed