【问题标题】:How can I hide the page links in the pagination class in Codeigniter?如何在 Codeigniter 的分页类中隐藏页面链接?
【发布时间】:2013-01-25 13:28:24
【问题描述】:

我正在尝试达到以下效果:

Prev 1 of 4 Next

我已尝试设置以下$config 选项:

$config['num_links'] = 0;

但我收到以下错误:

您的链接数必须为正数。

我的配置选项设置为:

    $config['base_url'] = "/browse/tag/$tid/";
    $config['total_rows'] = $num_items;
    $config['per_page'] = $max_items;
    $config['first_link'] = FALSE;
    $config['last_link'] = FALSE;
    $config['uri_segment'] = 4;
    $config['use_page_numbers'] = TRUE;
    $config['display_pages'] = TRUE;
    $config['num_links'] = 0; # this doesn't work
    $config['prev_link'] = 'Previous';
    $config['next_link'] = 'Next';
    $config['cur_tag_open'] = '<span>';
    $config['cur_tag_close'] = " of $pages</span>";
    $config['full_tag_open'] = '<div class="previousnext">';
    $config['full_tag_close'] = '</div>';

如果我将num_links 更改为 1,我显然会得到:

Prev 1 2 of 4 3 Next

如果我关闭display_pages,我会得到:

Prev Next

在这个阶段,我想避免修改核心代码。

【问题讨论】:

  • 注释 $config[num_links] 行
  • 默认为3,并显示&lt; 1 2 3 **4** 5 6 7 &gt;

标签: php codeigniter pagination


【解决方案1】:

如果您可以将数字链接放在 HTML 中退出但不显示,您可能只想使用 CSS 隐藏它们。

使用$config['num_tag_open'] 定义一个带有类的开放标签,例如:

$config['num_tag_open'] = '<div class="hidden">';

然后简单地添加一个 CSS:

.hidden { display: none; }

【讨论】:

    【解决方案2】:

    您需要通过在application/libraries 目录中创建MY_Pagination.php 文件来extend Pagination Class 并使用它来覆盖create_links() 函数,该函数负责回显页面列表。

    MY_Pagination.php

    class MY_Pagination extends CI_Pagination{
        public function __construct(){
            parent::__construct();
        }
    
        public function create_links(){
            //copy and paste the logic from system/libraries/Pagination.php
            //but reimplement lines ~258-296 (CI 2.1.3) 
        }
    }
    

    通过在您的应用程序目录中进行更改并扩展核心,您可以保护自己免受未来核心升级(例如从 2.1.3 到 3.0)的影响。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-17
      • 2019-11-17
      • 1970-01-01
      • 1970-01-01
      • 2014-08-22
      • 2014-05-26
      相关资源
      最近更新 更多