【问题标题】:Add condition in contain in cakephp 3 pagination在 cakephp 3 分页中添加条件
【发布时间】:2019-01-16 20:11:41
【问题描述】:

如何在包含中添加条件以在 Cakephp3 中分页。

这是我的代码:

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

感谢您的帮助。

【问题讨论】:

  • 一种方法是将查询对象传递给分页函数而不是模型。所以,就像$query = this->Bookings->find()->where(...)->contain(...); $bookings = $this->paginate($query);.

标签: php cakephp-3.0


【解决方案1】:

尝试在 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']);

【讨论】:

    猜你喜欢
    • 2016-06-03
    • 2015-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多