简体   繁体   English

CakePHP忽略$ paginate属性

[英]CakePHP ignoring $paginate property

I've just baked a simple CakePHP app, and I'm trying to customize how records are paginated. 我刚刚烘焙了一个简单的CakePHP应用程序,并且试图自定义记录的分页方式。 I have this action in my controller: 我在控制器中执行了以下操作:

public function index() {
    $this->Recipe->recursive = 0;
    $this->set('recipes', $this->Recipe->paginate());
}

This works fine with the default pagination. 使用默认分页效果很好。 I'm trying to customize the amount of rows returned and their order by using a class property called $paginate in the same controller: 我试图通过在同一控制器中使用名为$paginate的类属性来自定义返回的行数及其顺序:

public $paginate = array(
    'limit' => 1,
    'order' => array(
        'Recipe.title' => 'asc'
    )
);

However it's taking no effect at all. 但是,它根本不起作用。 The results still have the default limit and sort order. 结果仍然具有默认的限制和排序顺序。 I've also tried setting up $this->paginate in my action, however this seems to get ignored also: 我也尝试在操作中设置$this->paginate ,但这似乎也被忽略了:

public function index() {
    $this->paginate = array(
        'limit' => 1,
        'order' => array(
            'Recipe.title' => 'asc'
        )
    );
    $this->set('recipes', $this->Paginator->paginate());
}

What could be causing Cake to ignore the pagination options I'm setting? 是什么导致Cake忽略了我设置的分页选项? Does it perhaps do something funky when you bake the application which I'm not aware of? 当您烘烤我不知道的应用程序时,它是否可能会做一些时髦的事情?

Try 尝试

public function index() {
    $this->Paginator->settings = array(
        'limit' => 1,
        'order' => array(
            'Recipe.title' => 'asc'
        )
    );
    $this->set('recipes', $this->Paginator->paginate());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM