在CakePHP3中为Paginate添加条件

时间:2016-04-12 09:12:41

标签: cakephp pagination cakephp-3.0

如何在Cakephp3中为paginate添加条件..

这是我的代码:

 $this->paginate = [
        'contain' => ['Users']
        ];
        $proprietes = $this->paginate($this->Proprietes);

        $this->set(compact('proprietes'));
        $this->set('_serialize', ['proprietes']);

例如这样的东西: $this->paginate($this->Proprietes)->where(['status'=>'pending']);

感谢您的帮助。

3 个答案:

答案 0 :(得分:6)

Reading the documentation helps.阅读整个页面。它甚至包含示例代码:

angular.module('myApp')
.controller('MainCtrl', function ($scope,serviceAjax) {
 ...
});

答案 1 :(得分:6)

来自官方网站上的Bookmarker tutorial

public function index()
{
    $this->paginate = [
        'conditions' => [
            'Bookmarks.user_id' => $this->Auth->user('id')
             /* for a LIKE clause equivalent use :
             'Bookmarks.title LIKE ' => '%abc%' */
        ]
    ];
    $this->set('bookmarks', $this->paginate($this->Bookmarks));
    $this->set('_serialize', ['bookmarks']);
}

文档没有对分页中的条件说太多。这是link of the official documentation

答案 2 :(得分:0)

我这样解决了这个问题。希望它会起作用

public function viewProductList()
    {
        $shopProduct = $this->ShopProducts->find()->where(['deleted' => 0])->order(['products_id' => 'DESC']);
        $this->paginate = array(
            'limit' => 5,
        );
        $this->set('shopProduct', $this->paginate($shopProduct));

    }