【问题标题】:CodeIgniter Pagination Last Page IssueCodeIgniter 分页最后一页问题
【发布时间】:2013-11-13 09:39:45
【问题描述】:

我一直在寻找解决问题的方法,但找不到答案。我相信我的问题与通常其他人使用 codeigniter 的分页库所面临的问题不同。

我的数据库中有 15 条记录,我想用分页显示每页 5 条。以下是我的分页配置:

    $config["base_url"] = base_url() . "main";
    $config["total_rows"] = $total_row[0]['total'];
    $config["per_page"] = 5;
    $config["uri_segment"] = $this->uri->segment(2);
    $config['num_links'] = 2;
    $config['use_page_numbers'] = TRUE;

    $config['cur_tag_open'] = '<b>';
    $config['cur_tag_close'] = '</b>';

    $this->pagination->initialize($config);

现在分页显示如下:

1 2 3 >

如果我导航到第 2 页 我的 URL 将是 http://blablabla.com/blablabla/2 并且正确加载的数据也是分页将是

2 3 >

但是如果我转到最后一页,URL 将是http://blablabla.com/blablabla/3,这很好,加载的数据也正确,但分页将是

1 2 3 >

当我转到最后一页时,第一页链接将突出显示。我的配置有问题吗?

【问题讨论】:

  • 是这样吗? $config['num_links'] = 2; 试试改成 3?
  • 我试过改了,结果还是一样。我个人认为这不是问题,因为基于 CodeIgniter 的用户指南: $config['num_links'] = 2;您希望在所选页码之前和之后的“数字”链接数。例如,数字 2 将在两侧放置两个数字,如本页最顶部的示例链接所示。

标签: php codeigniter pagination


【解决方案1】:

我认为您需要更改:
$config["uri_segment"] = $this-&gt;uri-&gt;segment(2);

$config["uri_segment"] = 2;
因为您只需要在此处提及 uri-segment 编号,如果您这样输入 $this-> uri->segment(2) 系统会将段 2 的值作为 $config["uri_segment"] ,如果该段不存在,它将突出显示第一页作为当前页。

【讨论】:

  • 老兄,非常感谢...我想如果我把 2 放在那里,我实际上修复了段 = 2。现在它可以工作了! :)
猜你喜欢
  • 1970-01-01
  • 2015-04-27
  • 2017-12-17
  • 2011-04-04
  • 1970-01-01
  • 1970-01-01
  • 2017-03-04
  • 1970-01-01
相关资源
最近更新 更多