【问题标题】:CodeIgniter pagination with index functionCodeIgniter 带有索引功能的分页
【发布时间】:2017-06-22 08:30:34
【问题描述】:

我有一个产品列表,当我按下一个子类别时,它会加载该子类别中的所有产品并将索引用作:

http://localhost/ClickBasket/listproductscontroller/index?subcategory=4

因为它可以包含很多产品,所以我使用了 CI 的分页库。当我转到第二页或第三页时效果很好:

http://localhost/ClickBasket/listproductscontroller/index/1?subcategory=4
http://localhost/ClickBasket/listproductscontroller/index/2?subcategory=4

但是当我返回第一页时,它会丢失子类别的id:

http://localhost/ClickBasket/listproductscontroller/index

因此,在页面中找不到该子类别及其产品的数据。你如何解决这个问题?我还在学习 CodeIgniter 的分页库。

【问题讨论】:

  • 你能分享你的控制器逻辑吗?您可以在控制器中处理它

标签: php html codeigniter pagination


【解决方案1】:

试试

我的代码:

//pagination
 $this->load->library('pagination');
 $config['base_url']   = site_url('/ClickBasket/listproductscontroller/index');
 $config['total_rows'] = $this->db->query('SELECT FOUND_ROWS() count;')->row()->count;
 $config['per_page']   = 9;
 #$config['uri_segment'] = 4;
 $config['full_tag_open']        = "<ul class='pagination'>";
 $config['full_tag_close']       = "</ul>";
 $config['num_tag_open']         = '<li>';
 $config['num_tag_close']        = '</li>';
 $config['cur_tag_open']         = "<li class='disabled'><li class='active'><a href='#'>";
 $config['cur_tag_close']        = "<span class='sr-only'></span></a></li>";
 $config['next_tag_open']        = "<li>";
 $config['next_tagl_close']      = "</li>";
 $config['prev_tag_open']        = "<li>";
 $config['prev_tagl_close']      = "</li>";
 $config['first_tag_open']       = "<li>";
 $config['first_tagl_close']     = "</li>";
 $config['last_tag_open']        = "<li>";
 $config['page_query_string']    = true;
 $config['query_string_segment'] = 'page';
 $config['reuse_query_string']   = true;
 $config['use_page_numbers']     = true;
 $config['last_tagl_close']      = "</li>";
 $this->pagination->initialize($config);

【讨论】:

  • 非常感谢!但我唯一真正缺少的是“reuse_query_string”配置。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-22
  • 1970-01-01
  • 1970-01-01
  • 2011-09-20
  • 1970-01-01
相关资源
最近更新 更多