Class CArrayDataProvider
CArrayDataProvider implements a data provider based on a raw data array.
The CArrayDataProvider::$rawData
property contains all data that may be sorted and/or
paginated. CArrayDataProvider will supply the data after sorting and/or
pagination. You may configure the sort and pagination properties
to customize sorting and pagination behaviors.
Elements in the raw data array may be either objects (e.g. model objects) or
associative arrays (e.g. query results of DAO). Make sure to set the CArrayDataProvider::$keyField
property to the name of the field that uniquely identifies a data
record or false if you do not have such a field.
CArrayDataProvider may be used in the following way:
$rawData=Yii::app()->db->createCommand('SELECT * FROM tbl_user')->queryAll(); // or using: $rawData=User::model()->findAll(); $dataProvider=new CArrayDataProvider($rawData, array( 'id'=>'user', 'sort'=>array( 'attributes'=>array( 'id', 'username', 'email', ), ), 'pagination'=>array( 'pageSize'=>10, ), )); // $dataProvider->getData() will return a list of arrays.
Note: if you want to use the sorting feature, you must configure sort property so that the provider knows which columns can be sorted.
- CComponent
- CDataProvider implements IDataProvider
- CArrayDataProvider
Direct known subclasses
FileSystemObjectDataProviderCopyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.1.4
Located at x2engine/framework/web/CArrayDataProvider.php
public
|
|
protected
array
|
|
protected
array
|
|
protected
integer
|
#
calculateTotalItemCount( )
Calculates the total number of data items. This method simply returns the
number of elements in |
protected
|
#
sortData( array $directions )
Sorts the raw data according to the specified sorting instructions. After
calling this method, |
protected
mixed
|
#
getSortingFieldValue( mixed $data, array $fields )
Get field for sorting, using dot like delimiter in query. |
protected
array
|
#
getSortDirections( string $order )
Converts the "ORDER BY" clause into an array representing the sorting directions. |
getData(),
getId(),
getItemCount(),
getKeys(),
getPagination(),
getSort(),
getTotalItemCount(),
setData(),
setId(),
setKeys(),
setPagination(),
setSort(),
setTotalItemCount()
|
public
string
|
$keyField | 'id' |
#
the name of the key field. This is a field that uniquely identifies a data
record. In database this would be the primary key. Defaults to 'id'. If it's set
to false, keys of |
public
array
|
$rawData | array() |
#
the data that is not paginated or sorted. When pagination is enabled, this property usually contains more elements than data. The array elements must use zero-based integer keys. |
public
boolean
|
$caseSensitiveSort | true |
#
controls how sorting works. True value means that case will be taken into account. False value will lead to the case insensitive sort. Default value is true. |
$data,
$id,
$itemCount,
$keys,
$pagination,
$sort,
$totalItemCount
|