gpt4 book ai didi

php - 在 Codeigniter 分页中设置当前页面

转载 作者:行者123 更新时间:2023-12-03 18:46:30 24 4
gpt4 key购买 nike

下面是我的代码,我不知道为什么它总是将第一页保留为当前页。这就是 NEXT 链接也不起作用的原因。我也试过 $config['uri_segment'] = 1; 但没有用。问题出在哪里?

$data['mukkadam_list'] = $this->get_mukkadam();
$data['from'] = $from;
$data['to'] = $to;
$data['mukkadam'] = $mukkadam;
$url = base_url('Report/teee/'.$from.'/'.$to.'/'.$mukkadam);
$config['base_url'] = $url;
$config['per_page'] = 50;
// Reports is model.
$config['total_rows'] = $this->Reports->counter($data['from'],$data['to'],$data['mukkadam']);
$config['num_links'] = $config['total_rows']/50;

$this->load->library('pagination');
$this->pagination->initialize($config);

谢谢。 :)

最佳答案

每当您要在 Codeigniter 中实现分页时,您需要记住两件事:

第一件事与页面生成相关的配置实际上是:

    // Loads pagination library
$this->load->library('pagination');

// @params $url = your controller + method path
$config['base_url'] = base_url() . $url;

// @params $totalRows = Total result found in query
$config['total_rows'] = $totalRows;

// @params $perPage = In your case it is 50
$config['per_page'] = $perPage;

// @params $segment = This is what you are missing in your code. Segment is the factor from where system reads which page records need to be shown
$config['uri_segment'] = $segment;
$this->pagination->initialize($config);

第二件事 与设计部分相关的分页配置:

$config['full_tag_open'] = '<ul class="pagination  pagination-sm m-t-none m-b-none">';
$config['full_tag_close'] = '</ul>';
$config['prev_link'] = '<i class="fa fa-chevron-left"></i>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '<i class="fa fa-chevron-right"></i>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';

$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';

$config['first_link'] = '<i class="fa fa-chevron-left"></i> <i class="fa fa-chevron-left"></i>';
$config['last_link'] = '<i class="fa fa-chevron-right"></i><i class="fa fa-chevron-right"></i>';
$this->pagination->create_links();

这是我在我的项目中一直使用的运行脚本。工作正常。您需要检查初始化期间传递的 uri_segment

如果您遇到任何问题,请告诉我。

关于php - 在 Codeigniter 分页中设置当前页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43736704/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com