PHP Class yii\data\BaseDataProvider

Since: 2.0
Author: Qiang Xue ([email protected])
Inheritance: extends yii\base\Component, implements yii\data\DataProviderInterface
Show file Open project: yiisoft/yii2 Class Usage Examples

Public Properties

Property Type Description
$id an ID that uniquely identifies the data provider among all data providers. You should set this property if the same page contains two or more different data providers. Otherwise, the [[pagination]] and [[sort]] may not work properly.

Public Methods

Method Description
getCount ( ) : integer Returns the number of data models in the current page.
getKeys ( ) : array Returns the key values associated with the data models.
getModels ( ) : array Returns the data models in the current page.
getPagination ( ) : Pagination | false Returns the pagination object used by this data provider.
getSort ( ) : Sort | boolean Returns the sorting object used by this data provider.
getTotalCount ( ) : integer Returns the total number of data models.
prepare ( boolean $forcePrepare = false ) Prepares the data models and keys.
refresh ( ) Refreshes the data provider.
setKeys ( array $keys ) Sets the key values associated with the data models.
setModels ( array $models ) Sets the data models in the current page.
setPagination ( array | Pagination | boolean $value ) Sets the pagination for this data provider.
setSort ( array | Sort | boolean $value ) Sets the sort definition for this data provider.
setTotalCount ( integer $value ) Sets the total number of data models.

Protected Methods

Method Description
prepareKeys ( array $models ) : array Prepares the keys associated with the currently available data models.
prepareModels ( ) : array Prepares the data models that will be made available in the current page.
prepareTotalCount ( ) : integer Returns a value indicating the total number of data models in this data provider.

Method Details

getCount() public method

Returns the number of data models in the current page.
public getCount ( ) : integer
return integer the number of data models in the current page.

getKeys() public method

Returns the key values associated with the data models.
public getKeys ( ) : array
return 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.

getModels() public method

Returns the data models in the current page.
public getModels ( ) : array
return array the list of data models in the current page.

getPagination() public method

Note that you should call BaseDataProvider::prepare or BaseDataProvider::getModels first to get correct values of [[Pagination::totalCount]] and [[Pagination::pageCount]].
public getPagination ( ) : Pagination | false
return Pagination | false the pagination object. If this is false, it means the pagination is disabled.

getSort() public method

Returns the sorting object used by this data provider.
public getSort ( ) : Sort | boolean
return Sort | boolean the sorting object. If this is false, it means the sorting is disabled.

getTotalCount() public method

When [[pagination]] is false, this returns the same value as [[count]]. Otherwise, it will call BaseDataProvider::prepareTotalCount to get the count.
public getTotalCount ( ) : integer
return integer total number of possible data models.

prepare() public method

This method will prepare the data models and keys that can be retrieved via BaseDataProvider::getModels and BaseDataProvider::getKeys. This method will be implicitly called by BaseDataProvider::getModels and BaseDataProvider::getKeys if it has not been called before.
public prepare ( boolean $forcePrepare = false )
$forcePrepare boolean whether to force data preparation even if it has been done before.

prepareKeys() abstract protected method

Prepares the keys associated with the currently available data models.
abstract protected prepareKeys ( array $models ) : array
$models array the available data models
return array the keys

prepareModels() abstract protected method

Prepares the data models that will be made available in the current page.
abstract protected prepareModels ( ) : array
return array the available data models

prepareTotalCount() abstract protected method

Returns a value indicating the total number of data models in this data provider.
abstract protected prepareTotalCount ( ) : integer
return integer total number of data models in this data provider.

refresh() public method

After calling this method, if BaseDataProvider::getModels, BaseDataProvider::getKeys or BaseDataProvider::getTotalCount is called again, they will re-execute the query and return the latest data available.
public refresh ( )

setKeys() public method

Sets the key values associated with the data models.
public setKeys ( array $keys )
$keys array the list of key values corresponding to [[models]].

setModels() public method

Sets the data models in the current page.
public setModels ( array $models )
$models array the models in the current page

setPagination() public method

Sets the pagination for this data provider.
public setPagination ( array | Pagination | boolean $value )
$value array | Pagination | boolean the pagination to be used by this data provider. This can be one of the following: - a configuration array for creating the pagination object. The "class" element defaults to 'yii\data\Pagination' - an instance of [[Pagination]] or its subclass - false, if pagination needs to be disabled.

setSort() public method

Sets the sort definition for this data provider.
public setSort ( array | Sort | boolean $value )
$value array | Sort | boolean the sort definition to be used by this data provider. This can be one of the following: - a configuration array for creating the sort definition object. The "class" element defaults to 'yii\data\Sort' - an instance of [[Sort]] or its subclass - false, if sorting needs to be disabled.

setTotalCount() public method

Sets the total number of data models.
public setTotalCount ( integer $value )
$value integer the total number of data models.

Property Details

$id public property

an ID that uniquely identifies the data provider among all data providers. You should set this property if the same page contains two or more different data providers. Otherwise, the [[pagination]] and [[sort]] may not work properly.
public $id