【问题标题】:A question about the order of pagination关于分页顺序的问题
【发布时间】:2010-03-23 15:24:08
【问题描述】:

目前我正在使用 Cakephp 处理历史消息页面。我遇到了关于记录顺序的问题。在控制器中,关于分页的代码如下

$this->paginate['Msg'] = array('order'=>'Msg.created desc');
$msgs = $this->paginate('Msg');
$this->set('historymsgs',$msgs);

然后我得到了包含最新消息的第一页,如下所示:

tom:I'm eighteen.
Jerry:How old are you?
tom:Tom.
Jerry:what's your name?
tom:Hi nice to meet you too!
Jerry:Hello,nice to meet you!

但我需要的是消息的相反顺序。如何在此处附加Msg.created asc 的条件?

提前致谢。

【问题讨论】:

  • 在您的代码中将desc 更改为asc
  • @Col。弹片...远远不止一页,我需要在第一页显示最新消息。
  • 那又怎样? asc 有什么问题?
  • 所以最新消息会在最后一页!
  • 好的,好的。最新但顺序相反。好吧,您必须找到一种重新排序结果集的方法。如果它是普通的 PHP,我只会使用 rsort(),但由于它不是 php 而是蛋糕,你必须找到一种蛋糕方式。文档可能会有所帮助

标签: php cakephp pagination


【解决方案1】:

因此,简而言之,您希望第一页显示最近的历史记录但是,在每个页面上,您希望消息按时间顺序显示,而不是按时间倒序显示。

如果是这样,您可以尝试在每个页面的数据集上使用Set::sort()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-09
    • 2011-03-13
    • 1970-01-01
    • 2011-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-17
    相关资源
    最近更新 更多