Skip to content
PHP Ecosystem
Explore

DataProviderInterface

API reference › yii › data › DataProviderInterface

interfaceyii\data\DataProviderInterface
Since2.0
Sourceframework/data/DataProviderInterface.php
Implemented by 1 type

DataProviderInterface is the interface that must be implemented by data provider classes.

Data providers are components that sort and paginate data, and provide them to widgets such as GridView, ListView.

For more details and usage information on DataProviderInterface, see the guide article on data providers.

MethodDescriptionDefined by
getCount() abstractReturns the number of data models in the current page.DataProviderInterface
getKeys() abstractReturns the key values associated with the data models.DataProviderInterface
getModels() abstractReturns the data models in the current page.DataProviderInterface
getPagination() abstractDataProviderInterface
getSort() abstractDataProviderInterface
getTotalCount() abstractReturns the total number of data models.DataProviderInterface
prepare() abstractPrepares the data models and keys.DataProviderInterface
abstract public function getCount(): int

Returns the number of data models in the current page.

This is equivalent to count($provider->getModels()). When pagination is false, this is the same as totalCount.

Returns

int: The number of data models in the current page.

abstract public function getKeys(): array

Returns the key values associated with the data models.

Returns

array: The list of key values corresponding to models. Each data model in models is uniquely identified by the corresponding key value in this array.

abstract public function getModels(): array

Returns the data models in the current page.

Returns

array: The list of data models in the current page.

abstract public function getPagination(): yii\data\Pagination|false

Returns

Pagination|false: The pagination object. If this is false, it means the pagination is disabled.

abstract public function getSort(): yii\data\Sort|false

Returns

Sort|false: The sorting object. If this is false, it means the sorting is disabled.

abstract public function getTotalCount(): int

Returns the total number of data models.

When pagination is false, this is the same as count.

Returns

int: Total number of possible data models.

abstract public function prepare(bool $forcePrepare = false): mixed

Prepares the data models and keys.

This method will prepare the data models and keys that can be retrieved via getModels() and getKeys().

This method will be implicitly called by getModels() and getKeys() if it has not been called before.

Parameters

ParameterTypeDescription
$forcePrepareboolWhether to force data preparation even if it has been done before.

Returns

mixed