CakePHP分页和排序 [英] CakePHP paginate and order by

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

问题描述

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



我试图订购我的数据,但它不是那么好,kinda



这是我的代码:

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


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

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

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

解决方案

尝试

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


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



EDIT。恩,那就对了。蛋糕手册 excerpt:



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



所以order是第三个参数。 / p>

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

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

This is my code:

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

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. :/

解决方案

Try

$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:

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

So order is the third argument.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆