M
M
mr-zherart2014-10-30 13:25:49
Yii
mr-zherart, 2014-10-30 13:25:49

How to make CPagination fetch correctly?

Hello. There are 4 records in the database, 3 of them have parameters that must satisfy the selection and be displayed on the page in the pagination.
While for an example I deduce on one record.

$criteria = new CDbCriteria();	
$total = UserDonate::model()->count();
$pages = new CPagination($total);
$pages->pageSize = 1;
$pages->applyLimit($criteria);

Next comes the sample
$userDonate = Yii::app()->db->createCommand()
->select('name,lastname,donate,inhonor,date,country_code,country_name_ua')
->from('{{user}} user')
->join('{{user_donate}} ud', 'user.id=ud.user_id')
->join('{{countries}} country', 'user.country=country.id')
->limit($pages->pageSize, $pages->currentPage)
->where(array('and', 'ud.status=1', 'ud.prog_id=:prog_id'), array(':prog_id'=>$prog_id))
->queryAll();

But as a result, it takes 1 record (the first one that satisfies the condition) and that's it. I am sure that the problem is with the limit, help me figure it out. Thanks!!!
UPD I use the yiinfinite-scroll extension , and I need it with CPagination.
UPD2 It is interesting that if you throw out the request
->where(array('and', 'ud.status=1', 'ud.prog_id=:prog_id'), array(':prog_id'=>$prog_id))

then everything works. Only clear business works for all records.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rustamka Vorontsov, 2014-10-30
@rmfordev

Why not via www.yiiframework.com/doc/api/1.1/CActiveDataProvider ?

$dataProvider = CActiveDataProvider(
                'user',
                array(
                    'criteria'=>$criteria,
                    'pagination'=>array(
                        'pageSize'=>1,
                        //'pageVar' =>'page',
                    ),
                )
            );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question