CakePHP paginate and order by(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 分页和排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CakePHP 分页和排序
- PHP Count 布尔数组中真值的数量 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Laravel 仓库 2022-01-01
