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',
'order'=>'create_time DESC',
'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.
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.
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(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.
|
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. |
make sure you define your static (unchanging) criteria before you define your compare values.
This will work:
This won't work: