代码点火器分页最后一页问题


CodeIgniter Pagination Last Page Issue

我一直在寻找我的问题的解决方案,但我找不到答案。我相信我的问题与通常其他人在使用代码点火器的分页库时面临的问题不同。

我的数据库中有 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并且正确加载数据也将分

<1>2 3>

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

1 2 3>

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

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

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