Problem with CActiveDataProvider

Hi. I want to get last 10 records from database by using CActiveDataProvider. Here is my configuration:




	public function actionLast()

	{

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

		'criteria'=>array(

			'order'=>'id DESC',

        		'limit'=>10,

			),

		));

		$this->render('last',array(

			'dataProvider'=>$dataProvider

		));

	}



Тhe problem is that CActiveDataProvider returns all the records, not the last 10, but at least they are ordered. Am I missing something with the configuration?

What’s the generated SQL? Also, if you don’t want to use pagination, you should configure ‘pagination’=>false.

I don’t know if it’s by design… but “limit” functions only if pagination is set to false!

That’s because if pagination is not false, the pagination’s limit will be used instead.

I tryed this one:




                'pagination'=>array(

                    'pageSize'=>self::PAGE_SIZE,

                    'limit'=>1,

                ),



but I get this error: Property "CPagination.limit" is read only.

I set pagination to false and It works fine now. Thank you very much :)

@mdombla: for pagination, please set pageSize instead.

First let me tell you that this framework is great !!!

I would like to retreive first 100 rows but to display them in pages… 10 items per page…

Something like this would be usable:




                'pagination'=>array(

                    'pageSize'=>10,

                    'maxItem'=>100,

                ),



For this special feature, you need to override CActiveDataProvider::calculateTotalItemCount() as:




    protected function calculateTotalItemCount()

    {

        $count=CActiveRecord::model($this->modelClass)->count($this->getCriteria());

        return $count>100 ? 100 : $count;

    }