开发者

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'=>开发者_JAVA技巧;'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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜