dougu3591 2012-07-13 06:25
浏览 34
已采纳

CakePHP分页,如何使当前页面成为锚点

In my view I am using this code:

$numbers = $this->Paginator->numbers(array(
    'separator'     => '',
    'tag'           => 'li',
    'currentClass'  => 'active'
));

which outputs:

<li class="active">1</li>
<li><a href="/controller/action/page:2">2</a></li>
<li><a href="/controller/action/page:3">3</a></li>

This works pretty well, the only issue I have with it is that the current page is not a link. Is it possible to make the current page a link?

Thanks for reading.

  • 写回答

5条回答 默认 最新

  • douweilei2307 2012-07-13 16:45
    关注

    I implemented a class extension like Dave suggested, but instead of copying all the code from the original class, I did a string replace method instead, that way, if I update the CakePHP core library, this should fail pretty gracefully, where as copying all the code from the original Helper may cause loss of features, bug fixes, etc. Here is the class that I implemented:

    <?php
    
    class AppPaginatorHelper extends PaginatorHelper
    {
        public function numbers($options = array()) {
            $output = parent::numbers($options);
    
            // get the current page number, and create a link with it
            $current = $this->current();
            $currentLink = $this->link($current, array('page' => $current));
    
            // if you're using cake pre 2.1 you cannot change the current class with
            // the options array, so it will always be "current"
            $find = "<li class=\"current\">{$current}</li>";
            $replace = "<li class=\"active\">{$currentLink}</li>"; 
    
            $output = str_replace($find, $replace, $output);
    
            return $output;
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作