Reputation: 1304
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.
Upvotes: 3
Views: 10577
Reputation: 1477
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.
Upvotes: 6
Reputation: 2303
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));
}
Upvotes: 0
Reputation: 25698
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));
}
Upvotes: 9