views:

28

answers:

1

Hi all,

I am doing some self-learning about pagination in cakePHP 1.26.

In the PostsController, I have this code:

$this->set('views', $this->Testing->Reply->findAllBypost_id($id));

I am trying to alter the code for pagination purpose,
and this is what I have tried out:

$this->paginate=array('conditions'=>array('Reply.post_id'=>'0'), 'limit' => 4);
$w = $this->paginate($this->Testing->Reply); 
$this->set('views', $w);

I am not sure if this is the best way to do it, please comment.

+1  A: 

Looks right to me, ensure you use the paginator helper in your views to be able to use the pagination to it's fullest extent.

You can make that one less line with this and if post_id is an int then use an actual int. I would also refrain from calling your view variables something closely relating to actual objects or pieces of cakephp...

$this->paginate=array('conditions'=>array('Reply.post_id'=> 0), 'limit' => 4);
$this->set('data', $this->paginate($this->Testing->Reply));
xcezzz