# IndexAction

> IndexAction implements the API endpoint for listing multiple models.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [rest](/docs/api/yii/rest/index.md) › IndexAction

| class | `yii\rest\IndexAction` |
| --- | --- |
| Extends | [`Action`](/docs/api/yii/rest/action/index.md) » [`yii\base\Action`](/docs/api/yii/base/action/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\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/rest/IndexAction.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/rest/IndexAction.php#L29) |

IndexAction implements the API endpoint for listing multiple models.

For more details and usage information on IndexAction, see the [guide article on rest controllers](/docs/guide/rest-controllers/index.md).

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <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-checkAccess"></span>[`$checkAccess`](/docs/api/yii/rest/action/index.md#property-checkAccess) | `callable\|null` | A PHP callable that will be called when running an action to determine if the current user has the permission to execute the action. Default: `null`. | [`Action`](/docs/api/yii/rest/action/index.md) |
| <span id="property-controller"></span>[`$controller`](/docs/api/yii/base/action/index.md#property-controller) | `yii\base\T\|null` | The controller that owns this action, or `null` when the action runs standalone. via [`Module::$actionMap`](/docs/api/yii/base/module/index.md#property-actionMap) Default: `null`. | [`yii\base\Action`](/docs/api/yii/base/action/index.md) |
| [`$dataFilter`](#property-dataFilter) | [`yii\data\DataFilter`](/docs/api/yii/data/datafilter/index.md)`\|null` | Data filter to be used for the search filter composition. Default: `null`. Available since 2.0.13. | `IndexAction` |
| <span id="property-findModel"></span>[`$findModel`](/docs/api/yii/rest/action/index.md#property-findModel) | `callable\|null` | A PHP callable that will be called to return the model corresponding to the specified primary key value. Default: `null`. | [`Action`](/docs/api/yii/rest/action/index.md) |
| <span id="property-id"></span>[`$id`](/docs/api/yii/base/action/index.md#property-id) | `string\|null` | ID of the action; `null` between construction and dispatcher post-assignment for standalone actions resolved through [`Module::$actionMap`](/docs/api/yii/base/module/index.md#property-actionMap) or [`Module::$actionNamespace`](/docs/api/yii/base/module/index.md#property-actionNamespace). Default: `null`. | [`yii\base\Action`](/docs/api/yii/base/action/index.md) |
| <span id="property-modelClass"></span>[`$modelClass`](/docs/api/yii/rest/action/index.md#property-modelClass) | `string` | Class name of the model which will be handled by this action. Default: `null`. | [`Action`](/docs/api/yii/rest/action/index.md) |
| <span id="property-module"></span>[`$module`](/docs/api/yii/base/action/index.md#property-module) | [`yii\base\Module`](/docs/api/yii/base/module/index.md)`\|null` | The owning module, or `null` if neither a module nor a controller is attached. Available since 22.0. | [`yii\base\Action`](/docs/api/yii/base/action/index.md) |
| [`$pagination`](#property-pagination) | `array\|`[`yii\data\Pagination`](/docs/api/yii/data/pagination/index.md)`\|false` | The pagination to be used by [`prepareDataProvider()`](/docs/api/yii/rest/indexaction/index.md#method-prepareDataProvider). Default: `[]`. Available since 2.0.45. | `IndexAction` |
| [`$prepareDataProvider`](#property-prepareDataProvider) | `callable\|null` | A PHP callable that will be called to prepare a data provider that should return a collection of the models. Default: `null`. | `IndexAction` |
| [`$prepareSearchQuery`](#property-prepareSearchQuery) | `callable` | A PHP callable that will be called to prepare query in prepareDataProvider. Default: `null`. Available since 2.0.42. | `IndexAction` |
| [`$sort`](#property-sort) | `array\|`[`yii\data\Sort`](/docs/api/yii/data/sort/index.md)`\|false` | The sorting to be used by [`prepareDataProvider()`](/docs/api/yii/rest/indexaction/index.md#method-prepareDataProvider). Default: `[]`. Available since 2.0.45. | `IndexAction` |
| <span id="property-uniqueId"></span>[`$uniqueId`](/docs/api/yii/base/action/index.md#property-uniqueId) read-only | `string` | The unique ID of this action among the whole application. | [`yii\base\Action`](/docs/api/yii/base/action/index.md) |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/action/index.md#method-__construct) | Constructor. | [`yii\base\Action`](/docs/api/yii/base/action/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-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-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-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-findModel"></span>[`findModel()`](/docs/api/yii/rest/action/index.md#method-findModel) | Returns the data model based on the primary key given. | [`Action`](/docs/api/yii/rest/action/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-getModule"></span>[`getModule()`](/docs/api/yii/base/action/index.md#method-getModule) | Returns the module that owns this action when invoked standalone. | [`yii\base\Action`](/docs/api/yii/base/action/index.md) |
| <span id="method-getUniqueId"></span>[`getUniqueId()`](/docs/api/yii/base/action/index.md#method-getUniqueId) | Returns the unique ID of this action among the whole application. | [`yii\base\Action`](/docs/api/yii/base/action/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) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/rest/action/index.md#method-init) | Initializes the object. | [`Action`](/docs/api/yii/rest/action/index.md) |
| <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) |
| [`run()`](#method-run) |  | `IndexAction` |
| <span id="method-runWithParams"></span>[`runWithParams()`](/docs/api/yii/base/action/index.md#method-runWithParams) | Runs this action with the specified parameters. | [`yii\base\Action`](/docs/api/yii/base/action/index.md) |
| <span id="method-setModule"></span>[`setModule()`](/docs/api/yii/base/action/index.md#method-setModule) | Sets the module that owns this action when invoked standalone. | [`yii\base\Action`](/docs/api/yii/base/action/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-afterRun"></span>[`afterRun()`](/docs/api/yii/base/action/index.md#method-afterRun) protected | This method is called right after `run()` is executed. | [`yii\base\Action`](/docs/api/yii/base/action/index.md) |
| <span id="method-beforeRun"></span>[`beforeRun()`](/docs/api/yii/base/action/index.md#method-beforeRun) protected | This method is called right before `run()` is executed. | [`yii\base\Action`](/docs/api/yii/base/action/index.md) |
| [`prepareDataProvider()`](#method-prepareDataProvider) protected | Prepares the data provider that should return the requested collection of the models. | `IndexAction` |
| <span id="method-resolveStandaloneParams"></span>[`resolveStandaloneParams()`](/docs/api/yii/base/action/index.md#method-resolveStandaloneParams) protected | Resolves typed parameters of `run()` when the action is invoked without a hosting controller. | [`yii\base\Action`](/docs/api/yii/base/action/index.md) |

## Property details

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

```php
public yii\data\DataFilter|null $dataFilter = null
```

Data filter to be used for the search filter composition.

You must set up this field explicitly in order to enable filter processing.
For example:

```
[
    'class' => 'yii\data\ActiveDataFilter',
    'searchModel' => function () {
        return (new \yii\base\DynamicModel(['id' => null, 'name' => null, 'price' => null]))
            ->addRule('id', 'integer')
            ->addRule('name', 'trim')
            ->addRule('name', 'string')
            ->addRule('price', 'number');
    },
]
```

**Since**

2.0.13

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

```php
public array|yii\data\Pagination|false $pagination = []
```

The pagination to be used by [`prepareDataProvider()`](/docs/api/yii/rest/indexaction/index.md#method-prepareDataProvider).

If this is `false`, it means pagination is disabled.
Note: if a Pagination object is passed, it's `params` will be set to the request parameters.

**Since**

2.0.45

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

```php
public callable|null $prepareDataProvider = null
```

A PHP callable that will be called to prepare a data provider that should return a collection of the models.

If not set, [`prepareDataProvider()`](/docs/api/yii/rest/indexaction/index.md#method-prepareDataProvider) will be used instead.
The signature of the callable should be:

```
function (IndexAction $action) {
    // $action is the action object currently running
}
```

The callable should return an instance of [`ActiveDataProvider`](/docs/api/yii/data/activedataprovider/index.md).

If [`$dataFilter`](/docs/api/yii/rest/indexaction/index.md#property-dataFilter) is set the result of [`DataFilter::build()`](/docs/api/yii/data/datafilter/index.md#method-build) will be passed to the callable as a second parameter.
In this case the signature of the callable should be the following:

```
function (IndexAction $action, mixed $filter) {
    // $action is the action object currently running
    // $filter the built filter condition
}
```

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

```php
public callable $prepareSearchQuery = null
```

A PHP callable that will be called to prepare query in prepareDataProvider.

Should return $query.
For example:

```
function ($query, $requestParams) {
    $query->andFilterWhere(['id' => 1]);
    ...
    return $query;
}
```

**Since**

2.0.42

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

```php
public array|yii\data\Sort|false $sort = []
```

The sorting to be used by [`prepareDataProvider()`](/docs/api/yii/rest/indexaction/index.md#method-prepareDataProvider).

If this is `false`, it means sorting is disabled.
Note: if a Sort object is passed, it's `params` will be set to the request parameters.

**Since**

2.0.45

## Method details

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

```php
public function run(): yii\data\ActiveDataProvider
```

**Returns**

[`yii\data\ActiveDataProvider`](/docs/api/yii/data/activedataprovider/index.md)

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

```php
protected function prepareDataProvider(): yii\data\ActiveDataProvider
```

Prepares the data provider that should return the requested collection of the models.

**Returns**

[`yii\data\ActiveDataProvider`](/docs/api/yii/data/activedataprovider/index.md)