3

How can i add a condition to paginate in Cakephp3..

This is my code :

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

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

For example Something like this: $this->paginate($this->Proprietes)->where(['status'=>'pending']);

Thank you for help.

3 Answers 3

9

Reading the documentation helps. Read the whole page. It even contains example code:

public function index()
{
    $query = $this->Articles->find('popular')->where(['author_id' => 1]);
    $this->set('articles', $this->paginate($query));
}
3
  • 1
    The whole page?! That's a bit extreme.
    – pg.
    Feb 25, 2020 at 7:29
  • 1
    @pg.seriously? Did you even look at the page? Most of the page is example code and this specific page is a 1-3 minute read. This is not a lot of text. Programming has A LOT to do with reading and writing documentation. Most of the time people are just to lazy to spend a moment to read but waste the same amount of time to ask on SO.
    – floriank
    Feb 25, 2020 at 10:26
  • Sorry I was just being sarcastic!
    – pg.
    Feb 26, 2020 at 19:25
6

From the Bookmarker tutorial on the official website .

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']);
}

the documentation does not say too much about conditions in Pagination. Here is the link of the official documentation.

0

I solved this problem like this. Hope It will be work

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));

    }
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.