gpt4 book ai didi

Cakephp 3 同型号多分页?

转载 作者:行者123 更新时间:2023-12-05 06:40:02 24 4
gpt4 key购买 nike

我一直在做一个项目,但遇到了一个问题,即在 Cakephp 3 中,一个 View 需要在具有不同条件的同一模型上进行两次分页。

例如。在同一 View 中列出打开和关闭的支持工单。

以下是我的代码。有人可以帮助我吗?

//Opened status pagination
$opened_paginate = [
'contain' => ['Comments'],
'conditions' => [
'AND' => ['SupportTickets.status' => '1']
],
'order' => ['SupportTickets.id' => 'DESC'],
'limit' => 1
];

// Closed status pagination
$closed_paginate = [
'contain' => ['Comments'],
'conditions' => [
'AND' => ['SupportTickets.status' => '2']
],
'order' => ['SupportTickets.id' => 'DESC'],
'limit' => 1
];

$this->set('opened', $this->Paginator->paginate(
$this->SupportTickets->find(),
$opened_paginate
));
$this->set('closed', $this->Paginator->paginate(
$this->SupportTickets->find(),
$closed_paginate
));

最佳答案

您可以在单个操作中对不同的模型进行分页(请参阅 docs),但我认为这不适用于同一模型。

也许您可以使用 Traits 构建一些奇怪的东西或这个和那个,但我建议重新考虑您正在尝试做什么,并消除在单个 View 中多次对同一模型进行分页的需要。

You can paginate multiple models in a single controller action, using the scope option both in the controller’s $paginate property and in the call to the paginate() method:

// Paginate property
public $paginate = [
'Articles' => ['scope' => 'article'],
'Tags' => ['scope' => 'tag']
];

// In a controller action
$articles = $this->paginate($this->Articles, ['scope' => 'article']);
$tags = $this->paginate($this->Tags, ['scope' => 'tag']);
$this->set(compact('articles', 'tags'));

关于Cakephp 3 同型号多分页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43732157/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com