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

mus*_*sme 13 cakephp

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

我想在视图上显示此总计数,但count($recordsRetrieved)返回仅在当前页面上显示的数字.因此,如果检索到的记录总数为99且limit设置为10,则返回10,而不是99.

Moy*_*ari 19

您可以 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
)
*/
Run Code Online (Sandbox Code Playgroud)

PHP> = 5.4的最终代码:

$this->Paginator->params()['count'];

对于小于5.4的PHP版本:

$paginatorInformation = $this->Paginator->params();
$totalPageCount = $paginatorInformation['count'];
Run Code Online (Sandbox Code Playgroud)


Arz*_*rua 7

要获得您的答案,请访问以下链接 http://book.cakephp.org/2.0/en/controllers/request-response.html

使用pr($this->request->params)你会发现所有的分页东西


小智 6

对于蛋糕3.x

您可以使用方法 getPagingParams

例子:

debug($this->Paginator->getPagingParams());
Run Code Online (Sandbox Code Playgroud)

输出:

[
    'users' => [
        'finder' => 'all',
        'page' => (int) 1,
        'current' => (int) 5,
        'count' => (int) 5,
        'perPage' => (int) 1,
        'prevPage' => false,
        'nextPage' => true,
        'pageCount' => (int) 5,
        'sort' => null,
        'direction' => false,
        'limit' => null,
        'sortDefault' => false,
        'directionDefault' => false,
        'scope' => null
    ]
]
Run Code Online (Sandbox Code Playgroud)