1

I have a problem with the Cakephp2.3 paginator helper. In the 1.3 version, the paginate method was checking if the passed page param has a correct value. Now, it's not working anymore.

For example, if I have a list with 30 results, 10 items per page, then this was redirecting to the last (third) page:

mycontroller/index/page:130

Now, when I modify the url directly in the browser and pass an invalid page number, it just says there are no results.

This is how I'm using the paginate method:

$this->paginate = array(
                'limit' => 10,
                'order' => 'Appointment.start_datetime DESC'
            );
$appointments = $this->paginate('Appointment');

Is there something I'm missing?

Thank you in advance.

UPDATE

The paginator helper does know how to count the number of pages corectly, but it doesn't seem to care if a correct page number is passed. Here is the output from the view:

print_r($this->Paginator->params());

shows:

Array
(
    [page] => 1
    [current] => 10
    [count] => 30
    [prevPage] => 
    [nextPage] => 1
    [pageCount] => 3
    [order] => Appointment.start_datetime DESC
    [limit] => 10
    [options] => Array
        (
            [page] => 1
        )

    [paramType] => named
)
4

2 回答 2

1

似乎两个 Cake 版本都包含一些处理过高page参数的代码:

蛋糕1.3:Controller->paginate()

if ($page === 'last' || $page >= $pageCount) {
    $options['page'] = $page = $pageCount;
} elseif (intval($page) < 1) {
    $options['page'] = $page = 1;
}

蛋糕2.3:PaginatorComponent->paginate()

$pageCount = intval(ceil($count / $limit));
$page = max(min($page, $pageCount), 1);

但有趣的是,在 Cake 2.3 中,这段代码放在了对 的调用之后find(),所以来不及正确地获取记录。这可能是一个从未发出信号的错误。

于 2012-12-01T00:07:15.840 回答
0

我没有任何使用分页器的应用程序可以玩,所以这将是盲目的。您可以执行以下操作:

$page_count = $this->Paginator->params['paginator']['count'];
$page_requested = $this->request->params['paginator']['page'];

if($page_requested > $page_count){
    //Redirect to last page .....
}

虽然,我很难相信他们会在 2.x 中删除这个默认功能。

我会做一个pr($this->params);来获取您需要的分页器对象中的确切索引。

于 2012-11-30T10:47:05.700 回答