在cakephp 3分页中的包含中添加条件

时间:2019-01-05 14:09:18

标签: php cakephp-3.0

如何在Cakephp3中的contain中添加条件。

这是我的代码:

$this->paginate = [
'contain' => ['Users', 'AssignDrivers.Users', 'Invoices']
];
$bookings = $this->paginate($this->Bookings);   
$this->set(compact('bookings'));
$this->set('_serialize', ['bookings']);

例如这样的东西:

$this->paginate($this->bookings)->where(['Bookings.status'=>'pending', 'AssignDrivers.name LIKE'=>'%John%']);

谢谢您的帮助。

1 个答案:

答案 0 :(得分:0)

尝试在paginate()方法中使用条件。

$this->paginate = [
    'contain' => ['Users', 'AssignDrivers.Users', 'Invoices']
];

$bookings = $this->paginate(
    $this->Bookings->find()->where([
        'Bookings.status'=>'pending', 
        'AssignDrivers.name LIKE'=>'%John%'
    ])
);   

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