DataProviderInterface
API reference › yii › data › DataProviderInterface
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.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
getCount() abstract | Returns the number of data models in the current page. | DataProviderInterface |
getKeys() abstract | Returns the key values associated with the data models. | DataProviderInterface |
getModels() abstract | Returns the data models in the current page. | DataProviderInterface |
getPagination() abstract | DataProviderInterface | |
getSort() abstract | DataProviderInterface | |
getTotalCount() abstract | Returns the total number of data models. | DataProviderInterface |
prepare() abstract | Prepares the data models and keys. | DataProviderInterface |
Method details
Section titled “Method details”getCount()
Section titled “getCount() ”abstract public function getCount(): intReturns 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.
getKeys()
Section titled “getKeys() ”abstract public function getKeys(): arrayReturns the key values associated with the data models.
getModels()
Section titled “getModels() ”abstract public function getModels(): arrayReturns the data models in the current page.
Returns
array: The list of data models in the current page.
getPagination()
Section titled “getPagination() ”abstract public function getPagination(): yii\data\Pagination|falseReturns
Pagination|false: The pagination object. If this is false, it means the pagination is disabled.
getSort()
Section titled “getSort() ”abstract public function getSort(): yii\data\Sort|falseReturns
Sort|false: The sorting object. If this is false, it means the sorting is disabled.
getTotalCount()
Section titled “getTotalCount() ”abstract public function getTotalCount(): intReturns the total number of data models.
When pagination is false, this is the same as count.
Returns
int: Total number of possible data models.
prepare()
Section titled “prepare() ”abstract public function prepare(bool $forcePrepare = false): mixedPrepares 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
| Parameter | Type | Description |
|---|---|---|
$forcePrepare | bool | Whether to force data preparation even if it has been done before. |
Returns
mixed