Cactivedataprovider: Is It Possible To Limit The Number Of Records?

Hi All,

I want to use a CListView, I have created my CActiveDataProvider, but I cannot limit the number of records, the property ‘limit’ just doesn’t work here, I have checked this in the wiki.

In order to get this work, I haven’t used CListView, just CActiveRecord and foreach bucle, but I’m curious to know if there is a way to limit in CActiveDataProvider.

Saludos!

I figured something out…

Using pagination and template properties:




            //When you create your CActiveDataprovider:

            $dataProvider=new CActiveDataProvider('table', array(

                'pagination'=>array(

                    'pageSize'=>8,

                ),

            ));


            //When you use CListView, add this property:

            'template'=>"{items}",



The pager won’t be displayed, but now my doubt is… When we create the CActiveDataProvider, is it getting every single record of the table??? I mean… It won’t be so effective for the DB in case you have a lot of records in that table. Any opinion?

Saludos!

hi friends you can set limit

	$dataProvider=new CActiveDataProvider('model', array(


    'criteria'=>array(


    		'order'=>'create_time DESC',


 


),


			'pagination' => array('pageSize' => 8,),


			'totalItemCount' => 8,

));

it returns only 8 records from your database.