PHP Класс 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.
С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends BaseDataProvider
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$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.

Открытые методы

Метод Описание
init ( ) Initializes the DB connection component.
setSort ( $value )

Защищенные методы

Метод Описание
prepareKeys ( $models )
prepareModels ( )
prepareTotalCount ( )

Описание методов

init() публичный Метод

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

prepareKeys() защищенный Метод

protected prepareKeys ( $models )

prepareModels() защищенный Метод

protected prepareModels ( )

prepareTotalCount() защищенный Метод

protected prepareTotalCount ( )

setSort() публичный Метод

public setSort ( $value )

Описание свойств

$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.
public $db

$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.
См. также: getKeys()
public $key

$query публичное свойство

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