错误的 URL 导致分页
我正在使用 cakePHP 1.26。
在 PostsController 中,我有这个:
$this->paginate=array('conditions'=>array('Reply.post_id'=>$id),'limit' => 1);
$w = $this->paginate($this->Post->Reply);
$this->set('views', $w);
在 view.ctp 中,我有这个:
<table><tr><td>
<?php echo $paginator->numbers(); ?>
<?php
echo $paginator->prev('Previous', null, null);
echo $paginator->next(' Next', null, null);?>
</td></tr></table>
当我按下“下一步”链接时,显示了错误的 URL:
http://localhost:8080/post/view/page:2
正确的 URL应该是
http://localhost:8080/post/view/2/page:2
/post/view/ 之后引用该帖子的 ID 丢失了,
您能帮我解决这个问题吗?
我将其添加到 view.ctp 中:
$paginator->options(array('url' => $this->passedArgs));
现在“下一个”和“上一个”链接已更正,但是
下一个和上一个链接之间的数字仍然不正确。
以下是上一个和下一个链接之后的样子:
http://localhost:8080/post/view/2/page:2
但代表数字 1|2|3|4|5 的链接尚未更改:
http://localhost:8080/post/view/page:2
有什么想法吗?
编辑原因: 好的,
我更改了代码并得到了问题的新答案:
这是我的 view.ctp 文件中的代码:
<?php
$paginator->options(array('url' => '../view/'.$postid));
echo $paginator->numbers();
echo $paginator->prev('Previous', null, null);
echo $paginator->next(' Next', null, null);
?>
I am using cakePHP 1.26.
In the PostsController, I have this:
$this->paginate=array('conditions'=>array('Reply.post_id'=>$id),'limit' => 1);
$w = $this->paginate($this->Post->Reply);
$this->set('views', $w);
And in the view.ctp, I have this:
<table><tr><td>
<?php echo $paginator->numbers(); ?>
<?php
echo $paginator->prev('Previous', null, null);
echo $paginator->next(' Next', null, null);?>
</td></tr></table>
And when I pressed the "Next" link, a wrong URL was shown:
http://localhost:8080/post/view/page:2
The correct URL should be
http://localhost:8080/post/view/2/page:2
The ID referring the Post is missing after /post/view/
Could you help me fix the problem please?
I added this to the view.ctp:
$paginator->options(array('url' => $this->passedArgs));
Now the Next and Previous links are corrected, but the
numbers in between the Next and Previous links are still incorrect.
Here is what the Previous and Next links llok like afterwards:
http://localhost:8080/post/view/2/page:2
But the links representing the numbers 1|2|3|4|5 are not changed yet:
http://localhost:8080/post/view/page:2
Any ideas?
Edit reason:
OK,
I altered my code and got a new answer for the question:
Here is the code in my view.ctp file:
<?php
$paginator->options(array('url' => '../view/'.$postid));
echo $paginator->numbers();
echo $paginator->prev('Previous', null, null);
echo $paginator->next(' Next', null, null);
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在本手册页的底部附近,它解释了您必须做什么才能将您的参数包含在分页链接中。
http://book.cakephp.org/view/166/Pagination-in- Views
CakePHP 手册是你的朋友!
Near the bottom of this manual page it explains what you must do to have your arguments included in the pagination links.
http://book.cakephp.org/view/166/Pagination-in-Views
The CakePHP manual is your friend!