Pagination Has Stange Behaviour


My pagination doesn’t work as he should work.

here my code :

 public function search() {

        // Warning: Please modify the following code to remove attributes that

        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->with = array('projetsActif','tachesActif');

        $criteria->compare('tachesActif.tache_id', $this->fk_tache, true, 'AND');

        $criteria->compare('projetsActif.projet_id', $this->fk_projet, true, 'AND');

        $criteria->compare('fk_personne', $this->fk_personne, true, 'AND');

        // traitement date

        if ($this->date_debut == "") {

            $this->date_debut = helpers::getDateMin($this->date_debut);


        Yii::app()->setGlobalState('dateDebut', $this->date_debut);


        if ($this->date_fin == "") {

            $this->date_fin = helpers::getDateMax($this->date_fin);


            Yii::app()->setGlobalState('dateFin', $this->date_fin);



        $criteria->addBetweenCondition('date', helpers::setFormatDateForQges($this->date_debut), helpers::setFormatDateForQges($this->date_fin), 'AND');


       $criteria->together = true;

       // exit();

       $sort = new CSort(); 

       $sort->attributes = array(

            'defaultOrder' => array('date DESC'),

            'date' => array(

                'asc' => 'date',

                'desc' => 'date desc',


            'projetsActif' => array(

                'asc' => 'acronyme',

                'desc' => 'acronyme desc',


            'tachesActif' => array(

                'asc' => 'titre',

                'desc' => 'titre desc',


           'facture' => array(

                'asc' => 'facture',

                'desc' => 'facture desc',


           'personnesActif' => array(

                'asc' => 'NomPersonne',

                'desc' => 'NomPersonne desc',






         return new CActiveDataProvider($this, array(

                   'criteria' => $criteria,


                        'defaultOrder'=> 'date DESC',


                    'pagination' => array(

                        'pageSize' => 200,//Yii::app()->params->nbrElementParPage,




I put ;

‘pageSize’ => 200

but he display only 13 row and when I click to see the second page, I Have :

and the 3rd page :

any ideas?



Hi Nath,

It’s because the “LIMIT” is applied to the virtually joined single table, not to the main table.

If you do the eager loading (using ‘with’ and ‘together’), this is the expected result.

Please take a look at the following wiki. You will find why this should happen, and how to get the correct pagination.

thanks for your answer.

But I have the relation : BELONGS_TO.

return array(

            'projetsActif' => array(self::BELONGS_TO, 'TProjets', 'fk_projet'),

            'tachesActif' => array(self::BELONGS_TO, 'TTaches', 'fk_tache'),

            'personnesActif' => array(self::BELONGS_TO, 'TPersonnes', 'fk_personne'),


i tried the exemple in your link, but I canot find the solution ;-(

hoo I found the solution.

I just remove :

//        $criteria->with = array('projetsActif'=>array('select'=>false),

//                                'tachesActif'=>array('select'=>false));

thank for your help, but I still don’t understand very well relation even if I found the solution ;-(

But it will be comming, I think,More practise with yii

Ah, really?

I thought you were joining HAS_MANY relations, because pagination problems will occur typically with HAS_MANY relations.

If ‘projetsActiv’ and ‘tachesActif’ are BELONGS_TO relations, then there should be nothing complicated and your original code should have worked as expected.

But, hmm, the following looks a little strange.

I would write like this:

        $criteria->compare('t.fk_tache', $this->fk_tache, false, 'AND');

        $criteria->compare('t.fk_projet', $this->fk_projet, false, 'AND');