【问题标题】:How to limit db query data in CakePhp?如何限制 CakePhp 中的数据库查询数据?
【发布时间】:2010-07-01 09:53:18
【问题描述】:

我想在 CakePhp 上限制我的数据库数据。它可以通过 find 命令进行限制,但我不知道是否可以限制我的使用。这是我的 posts_controller.php 文件中的代码:

function index() {  
    $this->Post->order = array('order'=>'Post.date DESC','limit'=>5);  
    $this->Post->recursive = 0;  
    $this->set('posts', $this->paginate());  
}

【问题讨论】:

    标签: cakephp cakephp-1.3


    【解决方案1】:

    你可以试试:

    $this->paginate['Post'] = array('order'=>array('Post.date DESC'),'limit'=>5,'recursive'=>0);      
    $this->set('posts', $this->paginate('Post')); 
    

    有关详细信息,请参阅cookbook

    【讨论】:

    • 你很棒 SpawnCxy 非常感谢你。我是 CakePhp 的新手,所以还不能理解一些基础知识。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-01
    • 2011-07-06
    相关资源
    最近更新 更多