Yii Framework Forum: pagination problem - Yii Framework Forum

Jump to content

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

pagination problem Rate Topic: -----

#1 User is offline   dimis283 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 277
  • Joined: 24-January 09

Posted 24 February 2010 - 08:45 AM

I am trying to paginate articles but at all pages all articles are there.
what is wrong?
public function actionIndex() {
        if (!isset ($_GET['code']))
            $code=null;
        else {
            $code=$_GET['code'];
        }
        $cid=cats::model()->gerid($code);
        $criteria=new CDbCriteria;
        $criteria->condition='cat_id=:link';
        $criteria->params=array(':link'=>$cid);
        $criteria->order='art_short DESC';
      
            $postCount=Arts::model()->count($criteria);
$posts=Arts::model()->findAll($criteria);
        $pages=new CPagination($postCount);
        $pages->pageSize=$this->pageSize;
        $pages->applyLimit($criteria);
 
        $this->render('index',array(
               'posts'=>$posts,
                'pages'=>$pages,
        ));
      
    }

Posted Image
0

#2 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 751
  • Joined: 02-February 09

Posted 24 February 2010 - 09:32 AM

have you tried to populate your $post after you setup your $pages? What does the gerid() method represent? What value is $this->pageSize?
0

#3 User is offline   dimis283 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 277
  • Joined: 24-January 09

Posted 25 February 2010 - 03:11 AM

I actually set
 $pages->applyLimit($criteria);
 $criteria->limit =$this->pageSize;
 $criteria->offset=intval($pg);
 $posts=Arts::model()->findAll($criteria);

All my previous code was from blog demo, I do not know if I set it wrong.
Posted Image
0

#4 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 751
  • Joined: 02-February 09

Posted 25 February 2010 - 04:15 AM

View Postdimis283, on 25 February 2010 - 03:11 AM, said:

I actually set
 $pages->applyLimit($criteria);
 $criteria->limit =$this->pageSize;
 $criteria->offset=intval($pg);
 $posts=Arts::model()->findAll($criteria);

All my previous code was from blog demo, I do not know if I set it wrong.



so are you still experiencing a problem?
0

#5 User is offline   dimis283 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 277
  • Joined: 24-January 09

Posted 25 February 2010 - 04:54 AM

Since I set limit and offset , it is ok now
Posted Image
0

#6 User is offline   TAQTICA 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 13-February 10

Posted 25 February 2010 - 06:49 AM

I have the same problem and trying to understand code.

What is $pg?
0

#7 User is offline   dimis283 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 277
  • Joined: 24-January 09

Posted 25 February 2010 - 07:29 AM

 if (!isset($_GET['page']))
            $pg=1;
        else
            $pg=  intval($_GET['page']);

Posted Image
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