CakePHP 分页和排序

时间:2023-03-19
本文介绍了CakePHP 分页和排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感觉我已经尝试了一切,所以我现在来找你.

It feels like I've tried everything so I now come to you.

我正在尝试订购我的数据,但进展不顺利,对 Cake 来说有点新.

I am trying to order my data but it isn't going so well, kinda new to Cake.

这是我的代码:

$this->set('threads', $this->paginate('Thread', array(
        'Thread.hidden' => 0,
        'Thread.forum_category_id' => $id,
        'order' => array(
            'Thread.created' => 'desc'
        )
    )));

它生成一个 SQL 错误,这是最后一个有趣的部分:

It generates an SQL error and this is the last and interesting part:

AND `Thread`.`forum_category_id` = 12 AND order = ('desc') ORDER BY `Thread`.`created` ASC LIMIT 25

我该如何解决这个问题?创建的字段显然存在于数据库中.:/

How can I fix this? The field created obviously exists in the database. :/

推荐答案

尝试

$this->set('threads', $this->paginate('Thread', array(
        'Thread.hidden' => 0,
        'Thread.forum_category_id' => $id
    ),
    array(
        'Thread.created' => 'desc'
    )
));

我不是蛋糕大师,只是猜测.

I'm not a Cake master, just a guess.

编辑.是的,这是正确的.蛋糕 手册 摘录:

EDIT. Yes, thats right. Cake manual excerpt:

控制用于排序的字段...$this->paginate('Post', array(), array('title', 'slug'));

Control which fields used for ordering ... $this->paginate('Post', array(), array('title', 'slug'));

所以顺序是第三个参数.

So order is the third argument.

这篇关于CakePHP 分页和排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:引导程序 3 确认删除 cakephp 中的模式 下一篇:CakePHP:图片内链接,想让链接指向图片位置

相关文章

最新文章