【问题标题】:Show limited no. of page links in codeigniter pagination显示数量有限。 codeigniter 分页中的页面链接数
【发布时间】:2016-08-05 17:09:40
【问题描述】:

我想显示一个有限的编号。页面链接,比如说 10 个链接中的 5 个,codeIgniter 中是否有任何已知或经过验证的方法来实现这一点。

假设用户现在可以看到以下链接

prev, 1(selected), 2, 3, 4, 5... next

用户点击,比如说 4,现在他看到了

prev... 3, 4(selected), 5, 6, 7...next

现在他点击了 7

prev... 6, 7(selected), 8, 9, 10...next

如何在代码点火器中执行此操作?

提前致谢。

【问题讨论】:

  • 如果不告诉我你得到你的答案了吗......

标签: php codeigniter


【解决方案1】:

为此有一个内置的Pagination class

【讨论】:

    【解决方案2】:

    在 Libraries 文件夹中找到 Pagination Class 并编辑此变量:

    var $num_links
    

    【讨论】:

      【解决方案3】:

      codeIgniter 提供了一个内置的分页类。您可以在用户指南中找到它。

      在函数中定义一个起始索引变量,您希望在其中使用分页为零。

      public function pagination($start_index = 0)
      

      {

        $result = $this->model->get_results($data); //this $data is the argument which you are passing to your model function. If you are using database to get results array.
      
        $items_per_page = 10;   //this is constant variable which you need to define
      
        $filtered_result = array_splice($result, $start_index, ITEM_PER_PAGE_USERS);
      
        $model['$filtered_result'] = $filtered_result;
      
        $total_rows = count($result);
      
        $model['page_links'] = create_page_links (base_url()."/controlelr_name/pagination",ITEM_PER_PAGE_USERS, $total_rows);
      
        $this->load->view('controller_name/view_file_name', $model);
      

      }

       function create_page_links($base_url, $per_page, $total_rows) {
      
      $CI = & get_instance();
      $CI->load->library('pagination');
      
      $config['base_url'] = $base_url;
      $config['total_rows'] = $total_rows;
      $config['per_page'] = $per_page; 
      
      $CI->pagination->initialize($config); 
      
      return $CI->pagination->create_links();
      

      }

      此创建页面链接功能是一个通用功能......更多解释请查看用户指南中的pagination class......

      【讨论】:

        【解决方案4】:

        当你想修正分页页码时你修改$num_links:

        $config['total_rows'] =100;
        $config["num_links"] = 5;
        $config['full_tag_open'] = '<ul class="pagination">';
        $config['full_tag_close'] = '</ul>';
        $config['first_link'] = false;
        $config['last_link'] = false;
        

        显示如下:>

        【讨论】:

          猜你喜欢
          • 2011-07-09
          • 2013-06-13
          • 2015-02-23
          • 2013-05-03
          • 2013-04-07
          • 1970-01-01
          • 2020-02-14
          • 1970-01-01
          • 2020-09-04
          相关资源
          最近更新 更多