PHP Class yii\data\ActiveDataProvider

ActiveDataProvider provides data by performing DB queries using [[query]]. The following is an example of using ActiveDataProvider to provide ActiveRecord instances: php $provider = new ActiveDataProvider([ 'query' => Post::find(), 'pagination' => [ 'pageSize' => 20, ], ]); get the posts in the current page $posts = $provider->getModels(); And the following example shows how to use ActiveDataProvider without ActiveRecord: php $query = new Query(); $provider = new ActiveDataProvider([ 'query' => $query->from('post'), 'pagination' => [ 'pageSize' => 20, ], ]); get the posts in the current page $posts = $provider->getModels(); For more details and usage information on ActiveDataProvider, see the guide article on data providers.
Since: 2.0
Author: Qiang Xue ([email protected])
Inheritance: extends BaseDataProvider
Afficher le fichier Open project: yiisoft/yii2 Class Usage Examples

Méthodes publiques

Свойство Type Description
$db the DB connection object or the application component ID of the DB connection. If not set, the default DB connection will be used. Starting from version 2.0.2, this can also be a configuration array for creating the object.
$key the column that is used as the key of the data models. This can be either a column name, or a callable that returns the key value of a given data model. If this is not set, the following rules will be used to determine the keys of the data models: - If [[query]] is an ActiveQuery instance, the primary keys of [[\yii\db\ActiveQuery::modelClass]] will be used. - Otherwise, the keys of the [[models]] array will be used.
$query the query that is used to fetch data models and [[totalCount]] if it is not explicitly set.

Méthodes publiques

Méthode Description
init ( ) Initializes the DB connection component.
setSort ( $value )

Méthodes protégées

Méthode Description
prepareKeys ( $models )
prepareModels ( )
prepareTotalCount ( )

Method Details

init() public méthode

This method will initialize the [[db]] property to make sure it refers to a valid DB connection.
public init ( )

prepareKeys() protected méthode

protected prepareKeys ( $models )

prepareModels() protected méthode

protected prepareModels ( )

prepareTotalCount() protected méthode

protected prepareTotalCount ( )

setSort() public méthode

public setSort ( $value )

Property Details

$db public_oe property

the DB connection object or the application component ID of the DB connection. If not set, the default DB connection will be used. Starting from version 2.0.2, this can also be a configuration array for creating the object.
public $db

$key public_oe property

the column that is used as the key of the data models. This can be either a column name, or a callable that returns the key value of a given data model. If this is not set, the following rules will be used to determine the keys of the data models: - If [[query]] is an ActiveQuery instance, the primary keys of [[\yii\db\ActiveQuery::modelClass]] will be used. - Otherwise, the keys of the [[models]] array will be used.
See also: getKeys()
public $key

$query public_oe property

the query that is used to fetch data models and [[totalCount]] if it is not explicitly set.
public $query