Yii Framework Forum: Carraydataprovider With Query Findall() - Yii Framework Forum

Jump to content

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

Carraydataprovider With Query Findall() Rate Topic: -----

#1 User is offline   thangnguyen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 30-June 13

Posted 01 July 2013 - 12:05 AM

Hi Everyone,I'm new to Yii

When i do with CarrayDataProvider , i see this code
$rawData=Yii::app()->db->createCommand('SELECT * FROM tbl_user')->queryAll();
// or using: $rawData=User::model()->findAll();
$dataProvider=new CArrayDataProvider($rawData, array(
    'id'=>'user',
    'sort'=>array(
        'attributes'=>array(
             'id', 'username', 'email',
        ),
    ),
    'pagination'=>array(
        'pageSize'=>10,
    ),
));
// $dataProvider->getData() will return a list of arrays.

I want to know when first page reloads or i get the next page in CGridview ajax pagination , the above query is alway find all record or it's auto add "offset, limit" attribute, ?

thanks for your help
( sorry for my bad english)
0

#2 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 891
  • Joined: 19-February 13
  • Location:India

Posted 01 July 2013 - 12:41 AM

Hi,

please see it..

http://www.yiiplaygr...taview/gridView

Hope it will be helpful
Thanks,
Ankit Modi
Skype : amodi06
0

#3 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,082
  • Joined: 16-February 11
  • Location:Japan

Posted 01 July 2013 - 01:14 AM

Hi thangnguyen, welcome to the forum.

View Postthangnguyen, on 01 July 2013 - 12:05 AM, said:

I want to know when first page reloads or i get the next page in CGridview ajax pagination , the above query is alway find all record

Yes.

View Postthangnguyen, on 01 July 2013 - 12:05 AM, said:

or it's auto add "offset, limit" attribute, ?

No.
CArrayDataProvider always requires all the raw data without offset and limit.

You would be better use CActiveDataProvider whenever it's possible. It will automatically apply 'offset' and 'limit' according to the pagination to optimize the query.
0

#4 User is offline   thangnguyen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 30-June 13

Posted 01 July 2013 - 01:28 AM

View Postsoftark, on 01 July 2013 - 01:14 AM, said:

CArrayDataProvider always requires all the raw data without offset and limit.
You would be better use CActiveDataProvider whenever it's possible. It will automatically apply 'offset' and 'limit' according to the pagination to optimize the query.

Thanks.
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