user327712
user327712

Reputation: 3321

Pagination with hasmany association in CakePHP

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.

Upvotes: 0

Views: 821

Answers (1)

xxcezz
xxcezz

Reputation: 364

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

Upvotes: 1

Related Questions