duanfu7840 2009-09-02 07:44
浏览 57
已采纳

CakePHP:编号分页结果

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

  • 写回答

2条回答 默认 最新

  • duanruanxian5028 2009-09-02 09:22
    关注

    Try this in the view:

    <?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' 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++;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)