Yii Framework Forum: limit in CActiveDataProvider - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

limit in CActiveDataProvider Rate Topic: -----

#1 User is offline   Habibul Morsalin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 02-December 10
  • Location:Dhaka, Bangladesh

Posted 16 May 2011 - 01:10 AM

I faced some problem ,
when I use CActiveDataProvider I can't set limit in its criteria,

I try bellows code, but it is not working.....
$dataProvider=new CActiveDataProvider('MstTender',
array(
'criteria' => array(
'condition'=>'isActive=1',
'order' => 'lastDateSubmission DESC',
'limit' => 5,
),
)
);

please any idea?????
1

#2 User is offline   ressaince 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 163
  • Joined: 10-January 11
  • Location:Jakarta

Posted 16 May 2011 - 01:29 AM

you must set the offset
$dataProvider=new CActiveDataProvider('MstTender',
array(
'criteria' => array(
'condition'=>'isActive=1',
'order' => 'lastDateSubmission DESC',
'offset'=>0,
'limit' => 5,
),
)
);

take it or leave it
1

#3 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 16 May 2011 - 01:58 AM

Maybe the pagination override the limit.

Try with:


$dataProvider=new CActiveDataProvider('MstTender',
   array(
      'criteria' => array( 
          'condition'=>'isActive=1', 
          'order' => 'lastDateSubmission DESC',
      ),
      'pagination'=>array(
          'pageSize'=>'5'
      )
  
   )	
);

0

#4 User is offline   Habibul Morsalin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 02-December 10
  • Location:Dhaka, Bangladesh

Posted 18 May 2011 - 01:19 AM

thnx everybody,

I found my solutions

bellows code is work nicely...........

$dataProvider=new CActiveDataProvider('MstTender',
array(
'criteria' => array(
'condition'=>'isActive=1',
'order' => 'lastDateSubmission DESC',
),
'pagination' => array('pageSize' => 2,),
'totalItemCount' => 2,
)
);
0

#5 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 18 May 2011 - 09:06 AM

total item count is not needed...
0

#6 User is offline   HBK 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 06-December 11
  • Location:Bangalore

Posted 12 May 2012 - 04:36 AM

@zaccaria,

I have tried not using totalitemCount but its not helping to limit records. I am not sure what is the issue.


Regards,
Krupa Sagar.
0

#7 User is offline   angelozi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 12-October 11
  • Location:Turkey

Posted 10 September 2012 - 03:28 AM

CArraydataprovider available
For example,
 $criteria = array(
                'condition'=>'t.isActive = :active',
                'params' => array('active' => 1 ),
                'order' => 't.lastDateSubmission desc',
                'offset' => 0,
                'limit' => 30
            );
 $list = MstTender::model()->findAll($criteria);
                
                $_list = new CArrayDataProvider($list, array(
                            'id' => 'listid',
                            'keyField' => 'isid', /*table primary field name*/
                            'pagination'=>array(
                                'pageSize'=>5
                            ),
                        ));

0

#8 User is offline   alumi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 04-March 13

Posted 04 March 2013 - 01:57 AM

View Postzaccaria, on 16 May 2011 - 01:58 AM, said:

Maybe the pagination override the limit.

You are right.

We need to set 'pagination' to false, like this:
$dataProvider = new CActiveDataProvider(
	Book::model(),
	array(
		'criteria' => array(
			'limit' => 20,
			'order' => 'created DESC'
		),
		'pagination' => false
	)
);

3

#9 User is offline   datdit 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 12-January 13

Posted 04 March 2013 - 08:52 AM

View Postalumi, on 04 March 2013 - 01:57 AM, said:

You are right.

We need to set 'pagination' to false, like this:
$dataProvider = new CActiveDataProvider(
	Book::model(),
	array(
		'criteria' => array(
			'limit' => 20,
			'order' => 'created DESC'
		),
		'pagination' => false
	)
);



Thank you, very much
0

#10 User is offline   Alex D. 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 15-October 11
  • Location:Ukraine

Posted 29 June 2013 - 03:26 PM

View Postalumi, on 04 March 2013 - 01:57 AM, said:

You are right.

We need to set 'pagination' to false


Thanx! Had the same problem - found your solution!
0

#11 User is offline   Azma 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 04-July 13

Posted 21 July 2013 - 01:03 PM

View Postalumi, on 04 March 2013 - 01:57 AM, said:

You are right.

We need to set 'pagination' to false, like this:
$dataProvider = new CActiveDataProvider(
	Book::model(),
	array(
		'criteria' => array(
			'limit' => 20,
			'order' => 'created DESC'
		),
		'pagination' => false
	)
);


if pagination=>false limit works. is there another right way limit and pagination works together?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users