CDataProvider

I am still understanding the basics of Yii and one topic that continues to elude me is the class CDataProvider. Exactly how do I go about using it?

I know that I can use it for pagination, and that by calling new CDataProvider(‘classname’); It will gather all of the objects that belong to classname, but that is about the limit of my knowledge.

Does anyone know of a good guide to explain when to use CDataProvider and how to use it depth? I have tried a significant amount of googling but no avail.

Some examples of things that I would like to look for would be things such as:

  • specify sort order

  • load with another relational item (similar to the with() ) function from CActiveRecord

  • How does it integrate with the CDbCriteria class

  • When to use CDataProvider and when to use another class

Any help would be great, thank you.

Go to http://www.yiiframework.com/doc/api/1.1/CDataProvider.

But if you still have any doubt, just look at the Yii’s demos at your Yii Framework folder.

Happy coding.

CDataProvider is a generic (abtract) class. Your Questions aim at the CActiveDataProvider which extends CDataProvider. There you can work with ActiveRecord, specify a criteria and a sorter. I guess that covers your specified use cases.

You cannot use CDataProvider directly, it’s an abstract class.

You would extend your own DataProvider from CDataProvider, if you have a more complex way to gather your data and the predefined DataProviders like CActiveDataProvider, CSqlDataProvider, CArrayDataProvider do not suffice.