CakePHP:编号分页结果 [英] CakePHP: Numbered Paginated Results

查看:79
本文介绍了CakePHP:编号分页结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题有点.ky,但它是最好的,我可以提出在4在早上。我有一个链接表,我是分页,没有什么花哨。假设有100个链接显示20页,共5页。我如何计算每个链接从1开始,结束于20在第一页,如果我们跳到最后一页将是81到100.我有多个查询改变方向和ORDER BY的查询,因此这将是动态。完成使用CakePHP 1.2。例如:reddit.com

The title is a bit wonky but it's the best I could come up with at 4 in the morn'. I have a table of links that I am paginating, nothing fancy. Let's say there are 100 links that are displayed 20 a page for 5 pages. How can I number each link starting with 1 and ending with 20 on the first page and if we skipped to the last page would be 81 through 100. I have multiple queries changing the direction and ORDER BY of my queries so this would have to be dynamically. Done using CakePHP 1.2. An example of this would be reddit.com

推荐答案

在视图中尝试:

<?php debug($this->params['paging']); ?>

这将给你一些关于分页器当前状态的内部信息。例如,您会发现:

This'll give you a bit of inside information about the current status of the paginator. For example, you'll find this:

Array (
    [Model] => Array (
            [page] => 2
            ...
            [options] => Array (
                    [limit] => 20
                    ...

'limit'是每页的项目 c / c $ c>'page'是,页面。

使用这个信息,在输出中插入这样的计数器非常简单。

'limit' being the "items per page" and 'page' being, well, the page.
With this information it should be pretty trivial to insert this kind of counter into your output.

$page = $this->params['paging']['Model']['page'];
$limit = $this->params['paging']['Model']['options']['limit'];

$counter = ($page * $limit) - $limit + 1;

foreach ($models as $model) {
    echo $counter;

    // normal $model output

    $counter++;
}

这篇关于CakePHP:编号分页结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆