gpt4 book ai didi

CakePHP:如何获取分页检索的记录总数

转载 作者:行者123 更新时间:2023-12-03 23:17:31 25 4
gpt4 key购买 nike

当您使用 $this->paginate('Modelname') 检索记录时有一些页面limit ,如何获取检索到的记录总数?

我想在 View 中显示这个总数,但是 count($recordsRetrieved)返回仅显示在当前页面上的数字。因此,如果检索到的记录总数为 99 并且 limit设置为 10,它返回 10,而不是 99。

最佳答案

您可以 debug($this->Paginator->params());
这会给你

/*
Array
(
[page] => 2
[current] => 2
[count] => 43
[prevPage] => 1
[nextPage] => 3
[pageCount] => 3
[order] =>
[limit] => 20
[options] => Array
(
[page] => 2
[conditions] => Array
(
)
)
[paramType] => named
)
*/

PHP >=5.4 的最终代码:
$this->Paginator->params()['count'];
对于低于 5.4 的 PHP 版本:
$paginatorInformation = $this->Paginator->params();
$totalPageCount = $paginatorInformation['count'];

关于CakePHP:如何获取分页检索的记录总数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17093612/

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