CActiveDataProvider
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:
$dataProvider=new CActiveDataProvider('Post', array(
'criteria'=>array(
'condition'=>'status=1 AND tags LIKE :tags',
'params'=>array(':tags'=>$_GET['tags']),
'with'=>array('author'),
),
'pagination'=>array(
'pageSize'=>20,
),
));
// $dataProvider->getData() will return a list of Post objects
Property Details
the query criteria
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.
public string $modelClass;
the primary ActiveRecord class name. The getData() method
will return a list of objects of this class.
the sorting object. If this is false, it means the sorting is disabled.
Method Details
|
public void __construct(string $modelClass, array $config=array (
))
|
| $modelClass |
string |
the model class. This will be assigned to the modelClass property. |
| $config |
array |
configuration (name=>value) to be applied to this data provider.
Any public properties of the data provider can be configured via this parameter |
Constructor.
|
protected integer calculateTotalItemCount()
|
| {return} |
integer |
the total number of data items. |
Calculates the total number of data items.
|
protected array fetchData()
|
| {return} |
array |
list of data items |
Fetches the data from the persistent data storage.
|
protected array fetchKeys()
|
| {return} |
array |
list of data item keys. |
Fetches the data item keys from the persistent data storage.
|
|
| {return} |
CSort |
the sorting object. If this is false, it means the sorting is disabled. |
|
public void setCriteria(mixed $value)
|
| $value |
mixed |
the query criteria. This can be either a CDbCriteria object or an array
representing the query criteria. |