CActiveDataProvider
Package | system.web |
---|---|
Inheritance | class CActiveDataProvider » CDataProvider » CComponent |
Implements | IDataProvider |
Since | 1.1 |
Version | $Id: CActiveDataProvider.php 2178 2010-06-10 03:49:18Z qiang.xue $ |
CActiveDataProvider implements a data provider based on ActiveRecord.
CActiveDataProvider provides data in terms of ActiveRecord objects which are of class modelClass. It uses the AR CActiveRecord::findAll method to retrieve the data from database. The criteria property can be used to specify various query options, such as conditions, sorting, pagination, etc.
CActiveDataProvider may be used in the following way:
CActiveDataProvider provides data in terms of ActiveRecord objects which are of class modelClass. It uses the AR CActiveRecord::findAll method to retrieve the data from database. The criteria property can be used to specify various query options, such as conditions, sorting, pagination, etc.
CActiveDataProvider may be used in the following way:
$dataProvider=new CActiveDataProvider('Post', array( 'criteria'=>array( 'condition'=>'status=1', 'order'=>'create_time DESC', 'with'=>array('author'), ), 'pagination'=>array( 'pageSize'=>20, ), )); // $dataProvider->getData() will return a list of Post objects
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
criteria | CDbCriteria | the query criteria | CActiveDataProvider |
data | array | Returns the data items currently available. | CDataProvider |
id | string | the unique ID that uniquely identifies the data provider among all data providers. | CDataProvider |
itemCount | integer | Returns the number of data items in the current page. | CDataProvider |
keyAttribute | string | the name of key attribute for modelClass. | CActiveDataProvider |
keys | array | Returns the key values associated with the data items. | CDataProvider |
model | CActiveRecord | the AR finder instance (e. | CActiveDataProvider |
modelClass | string | the primary ActiveRecord class name. | CActiveDataProvider |
pagination | CPagination | the pagination object. | CDataProvider |
sort | CSort | the sorting object. | CActiveDataProvider |
totalItemCount | integer | Returns the total number of data items. | CDataProvider |
Public Methods
Method | Description | Defined By |
---|---|---|
__call() | Calls the named method which is not a class method. | CComponent |
__construct() | Constructor. | CActiveDataProvider |
__get() | Returns a property value, an event handler list or a behavior based on its name. | CComponent |
__isset() | Checks if a property value is null. | CComponent |
__set() | Sets value of a component property. | CComponent |
__unset() | Sets a component property to be null. | CComponent |
asa() | Returns the named behavior object. | CComponent |
attachBehavior() | Attaches a behavior to this component. | CComponent |
attachBehaviors() | Attaches a list of behaviors to the component. | CComponent |
attachEventHandler() | Attaches an event handler to an event. | CComponent |
canGetProperty() | Determines whether a property can be read. | CComponent |
canSetProperty() | Determines whether a property can be set. | CComponent |
detachBehavior() | Detaches a behavior from the component. | CComponent |
detachBehaviors() | Detaches all behaviors from the component. | CComponent |
detachEventHandler() | Detaches an existing event handler. | CComponent |
disableBehavior() | Disables an attached behavior. | CComponent |
disableBehaviors() | Disables all behaviors attached to this component. | CComponent |
enableBehavior() | Enables an attached behavior. | CComponent |
enableBehaviors() | Enables all behaviors attached to this component. | CComponent |
evaluateExpression() | Evaluates a PHP expression or callback under the context of this component. | CComponent |
getCriteria() | CActiveDataProvider | |
getData() | Returns the data items currently available. | CDataProvider |
getEventHandlers() | Returns the list of attached event handlers for an event. | CComponent |
getId() | CDataProvider | |
getItemCount() | Returns the number of data items in the current page. | CDataProvider |
getKeys() | Returns the key values associated with the data items. | CDataProvider |
getPagination() | CDataProvider | |
getSort() | CActiveDataProvider | |
getTotalItemCount() | Returns the total number of data items. | CDataProvider |
hasEvent() | Determines whether an event is defined. | CComponent |
hasEventHandler() | Checks whether the named event has attached handlers. | CComponent |
hasProperty() | Determines whether a property is defined. | CComponent |
raiseEvent() | Raises an event. | CComponent |
setCriteria() | CActiveDataProvider | |
setData() | CDataProvider | |
setId() | CDataProvider | |
setKeys() | CDataProvider | |
setPagination() | CDataProvider | |
setSort() | CDataProvider | |
setTotalItemCount() | Sets the total number of data items. | CDataProvider |
Protected Methods
Method | Description | Defined By |
---|---|---|
calculateTotalItemCount() | Calculates the total number of data items. | CActiveDataProvider |
fetchData() | Fetches the data from the persistent data storage. | CActiveDataProvider |
fetchKeys() | Fetches the data item keys from the persistent data storage. | CActiveDataProvider |
Property Details
criteria
property
the query criteria
keyAttribute
property
public string $keyAttribute;
the name of key attribute for modelClass. If not set, it means the primary key of the corresponding database table will be used.
model
property
(available since v1.1.3)
public CActiveRecord $model;
the AR finder instance (e.g. Post::model()
).
This property can be set by passing the finder instance as the first parameter
to the constructor.
modelClass
property
public string $modelClass;
the primary ActiveRecord class name. The getData() method will return a list of objects of this class.
sort
property
the sorting object. If this is false, it means the sorting is disabled.
Method Details
__construct()
method
public void __construct(mixed $modelClass, array $config=array (
))
| ||
$modelClass | mixed | the model class (e.g. 'Post') or the model finder instance
(e.g. Post::model() , Post::model()->published() ). |
$config | array | configuration (name=>value) to be applied as the initial property values of this class. |
Constructor.
calculateTotalItemCount()
method
protected integer calculateTotalItemCount()
| ||
{return} | integer | the total number of data items. |
Calculates the total number of data items.
fetchData()
method
protected array fetchData()
| ||
{return} | array | list of data items |
Fetches the data from the persistent data storage.
fetchKeys()
method
protected array fetchKeys()
| ||
{return} | array | list of data item keys. |
Fetches the data item keys from the persistent data storage.
getCriteria()
method
public CDbCriteria getCriteria()
| ||
{return} | CDbCriteria | the query criteria |
getSort()
method
public CSort getSort()
| ||
{return} | CSort | the sorting object. If this is false, it means the sorting is disabled. |
setCriteria()
method
public void setCriteria(mixed $value)
| ||
$value | mixed | the query criteria. This can be either a CDbCriteria object or an array representing the query criteria. |