CakePHP 分页和排序

CakePHP paginate and order by(CakePHP 分页和排序)
本文介绍了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 分页和排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Codeigniter htaccess to remove index.php and www(Codeigniter htaccess 删除 index.php 和 www)
htaccess mod_rewrite part of url to GET variable(htaccess mod_rewrite url 的一部分到 GET 变量)
Replacing a querystring parameter value using mod_rewrite(使用 mod_rewrite 替换查询字符串参数值)
.htaccess in subdirectory #39;overriding#39; parent htaccess(子目录“覆盖父 htaccess 中的 .htaccess)
How to rewrite SEO friendly url#39;s like stackoverflow(如何像stackoverflow一样重写SEO友好的url)
Is it okay to have a very long .htaccess file?(有一个很长的 .htaccess 文件可以吗?)