Yii Framework Forum: Pagination Has Stange Behaviour - Yii Framework Forum

Jump to content

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

Pagination Has Stange Behaviour Rate Topic: -----

#1 User is offline   nath-0 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 12-October 12
  • Location:switzerland

Posted 04 January 2013 - 04:11 AM

hello,

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);
        }else{
            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',
            ),
        );
        $sort->applyOrder($criteria);
        
        
         return new CActiveDataProvider($this, array(
                   'criteria' => $criteria,
                   'sort'=>array(
                        '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 :

Quote

Afficher les résultats de 201 à 217 (total de 2613)

and the 3rd page :

Quote

Afficher les résultats de 401 à 414 (total de 2613)


any ideas?

Thanks

Nath
0

#2 User is offline   softark 

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

Posted 04 January 2013 - 04:47 AM

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.
http://www.yiiframew..._many-relation/
0

#3 User is offline   nath-0 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 12-October 12
  • Location:switzerland

Posted 04 January 2013 - 05:44 AM

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 ;-(
0

#4 User is offline   nath-0 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 12-October 12
  • Location:switzerland

Posted 04 January 2013 - 05:52 AM

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
0

#5 User is offline   softark 

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

Posted 04 January 2013 - 07:23 AM

View Postnath-0, on 04 January 2013 - 05:44 AM, said:

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'),
        );


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.

Quote

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



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');

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