我正在使用 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));
现在 Next 和 Previous 链接已更正,但
Next 和 Previous 链接之间的数字仍然不正确。
以下是上一个和下一个链接之后的样子:
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);
?>