問題描述
感覺我已經嘗試了一切,所以我現在來找你.
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模板網!