开发者

Wrong URL resulted in pagination

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 corr开发者_如何学运维ected, 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);    
?> 


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!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜