CakePHP忽略$ paginate属性 [英] CakePHP ignoring $paginate property

查看:115
本文介绍了CakePHP忽略$ paginate属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚烘焙了一个简单的CakePHP应用程序,我试图自定义记录如何分页。我在我的控制器中有此操作:

I've just baked a simple CakePHP app, and I'm trying to customize how records are paginated. I have this action in my controller:

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

这与默认分页一样正常。我试图通过在同一控制器中使用类属性 $ 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:

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

但是它根本没有效果。结果仍具有默认限制和排序顺序。我也尝试在我的行动中设置 $ this-> paginate ,但这似乎也被忽略:

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:

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

可能导致Cake忽略我设置的分页选项?

What could be causing Cake to ignore the pagination options I'm setting? Does it perhaps do something funky when you bake the application which I'm not aware of?

推荐答案

尝试

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

这篇关于CakePHP忽略$ paginate属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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