CakePHP 中具有 hasmany 关联的分页
我正在自学 cakePHP 1.26 中的分页。
在 PostsController 中,我有以下代码:
$this->set('views', $this->Testing->Reply->findAllBypost_id($id));
我正在尝试更改用于分页目的的代码,
这是我尝试过的:
$this->paginate=array('conditions'=>array('Reply.post_id'=>'0'), 'limit' => 4);
$w = $this->paginate($this->Testing->Reply);
$this->set('views', $w);
我不确定这是否是最好的方法,请发表评论。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来是正确的,确保您在视图中使用分页器助手,以便能够最大程度地使用分页。
你可以用这个少一行,如果 post_id 是一个 int ,那么使用一个实际的 int 。我也不会将您的视图变量称为与实际对象或蛋糕密切相关的东西php......
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...