In Yii, why use CActiveDataProvider instead of Post :: model () & # 8594; findAll ()?

I see the CActiveDataProvider used in the actionIndex() controller function.

Is there any difference between using this instead of a simple Post::model()->findAll() ?

+4
source share
1 answer

CActiveDataProvider is a wrapper for CActiveRecord with advanced sorting , pagination and filtering capabilities. Typically, CActiveDataProvider used in conjunction with zii widgets, such as CListView or CGridView , which use their sorting and search capabilities. Therefore, if you want to display data in terms of a list or table using (optional) sorting / filtering / pagination - the most convenient way to do this in Yii is to use the described zii widgets or their extensions.

If you just need to extract the data and use it in some other way, but without the smart rendering mechanisms provided by CListView or CGridView , use CActiveRecord because it does nothing but select the data.

link

+3
source

All Articles