【问题标题】:PHP CodeIgniter Pagination link brokenPHP CodeIgniter 分页链接断开
【发布时间】:2011-12-03 04:04:33
【问题描述】:
public function index($page = 0) {
    $this->load->library('pagination');
    $conf = array(
        'total_rows' => 11,
        'base_url' => 'localhost/admin/product/index',
        'per_page' => 10,
        'use_page_numbers' => false
    );
    $this->pagination->initialize($conf);
    $this->load->view('product/index');
}

在视图中

<?php echo $this->pagination->create_links(); ?>

在第一页它可以正常工作。当我点击第2页链接时,它只显示一个产品,这是正确的,但当前页面的分页链接仍在第一个页面中。假设这应该是第二页。

我做错了哪一部分?

【问题讨论】:

  • 嗯,分页类没有加密
  • 我意识到我的 uri_segment 是 4。但是,默认分页 uri_segment 是 3。因此只需这样做:$conf['uri_segment'] = 4;

标签: php codeigniter pagination initialization broken-links


【解决方案1】:

好吧,分页类在查询字符串中使用“per_page”。因此,您必须将该数字除以 10(在您的情况下)并加 1 以获得真实的页码,即:

localhost/product/index (page 1)
localhost/product/index?per_page=10 (page 2)
localhost/product/index?per_page=20 (page 3)
...
localhost/product/index?per_page={10n) (page n+1)

这对于直接在数据库限制子句中使用很有用:

$this->db->limit(10, $this->input->get('per_page'))...

我认为这就是 CI 选择这样做的原因....

【讨论】:

  • CI_Pagination 对象 ( [base_url] => localhost/project/admin/product/index [prefix] => [suffix] => [total_rows] => 11 [per_page] => 10 [num_links] => 2 ...这是Pagination对象的配置,我还是查不出来问题。
  • 我发现了问题,我在上面评论过的答案。无论如何感谢您的回答。
  • 这令人沮丧。没有意识到您使用的是段而不是查询字符串。那好吧。为努力点赞? ;)
猜你喜欢
  • 2013-01-09
  • 1970-01-01
  • 2014-01-29
  • 1970-01-01
  • 1970-01-01
  • 2012-05-14
  • 2013-11-17
  • 2020-07-29
相关资源
最近更新 更多