使用codeigniter中的下一个和上一个按钮进行分页

我尝试使用以下代码在 CodeIgniter 中添加分页,它带有 1 2 3 4 5 > 这种格式。但我需要添加下一个和上一个按钮。控制器:


public function chooseBale($program_id = '')

{

    $config                = [];

    $config["base_url"]    = base_url() . "ginner/choosebale/" . $program_id;

    $config["total_rows"]  = $this->GinnerModel->get_count();

    $config["per_page"]    = 10;

    $config["uri_segment"] = 2;

    $choice                = $config["total_rows"] / $config["per_page"];

    $config["num_links"]   = round($choice);

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

    $page          = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;

    $data["links"] = $this->pagination->create_links();


    $data['pg_title']   = 'Choose Bale';

    $data['breadcrumb'] = ['Home' => '', 'Sale' => 'nolink', 'New Process' => 'nolink', 'Choose Bale' => 'nolink'];

    $data['left_menu']  = "left-menu-ginner.php";

    $data['program']    = $this->CommonModel->getTableWhere(PROGRAM, 'id =' . $program_id);

    $data['program_id'] = $program_id;

    $data['bale_list']  = $this->GinnerModel->baleList($program_id, $config["per_page"], $page);

    $this->load->view('common/header', $data);

    $this->load->view('ginner/choose-bale');

    $this->load->view('common/footer');

}

我在模型文件中使用了以下查询来获取限制明智的记录。模型:


public function baleList($program_id, $per_page, $page)

{

    $this->db->select('gp.id, gp.lot_no, SUM(gb.weight) AS weight, SUM(gb.staple) AS staple, SUM(gb.mic) AS mic, SUM(gb.strength) AS strength, SUM(gb.trash) AS trash, gb.color_grade');

    $this->db->from(GIN_BALES . ' gb');

    $this->db->join(GIN_PROCESS . ' gp', 'gp.id=gb.process_id');

    $this->db->where('gb.sold_status', 0);

    $this->db->where('gp.ginner_id', $this->prscr_id);

    $this->db->where('gp.program', $program_id);

    $this->db->group_by('gp.id');

看法:


<p><?php echo $links; ?></p>

我在查看页面代码的表格下添加了此链接代码。分页工作到箭头到达第一页后的 5 个部分。所以我无法查看分页的第 6 页。是否需要在控制器或模型文件中进行其他更正才能以正确的方式显示分页?


皈依舞
浏览 133回答 2
2回答

当年话下

见下面的代码,我们通过配置库配置分页链接&nbsp; &nbsp; $this->load->library("pagination");&nbsp; &nbsp; $config = array();&nbsp; &nbsp; $config["base_url"] = base_url() . "blogs";&nbsp; &nbsp; $config["total_rows"] = $this->blog->getBlogCount();&nbsp; &nbsp; $config["per_page"] = 10;&nbsp; &nbsp; $config["uri_segment"] = 2;&nbsp; &nbsp; $config['full_tag_open'] = "<ul class='pagination'>";&nbsp; &nbsp; $config['full_tag_close'] = '</ul>';&nbsp; &nbsp; $config['num_tag_open'] = '<li>';&nbsp; &nbsp; $config['num_tag_close'] = '</li>';&nbsp; &nbsp; $config['cur_tag_open'] = '<li class="active"><a href="#">';&nbsp; &nbsp; $config['cur_tag_close'] = '</a></li>';&nbsp; &nbsp; $config['prev_tag_open'] = '<li>';&nbsp; &nbsp; $config['prev_tag_close'] = '</li>';&nbsp; &nbsp; $config['first_tag_open'] = '<li>';&nbsp; &nbsp; $config['first_tag_close'] = '</li>';&nbsp; &nbsp; $config['last_tag_open'] = '<li>';&nbsp; &nbsp; $config['last_tag_close'] = '</li>';&nbsp; &nbsp; $config['prev_link'] = 'Previous';&nbsp; &nbsp; $config['prev_tag_open'] = '<li>';&nbsp; &nbsp; $config['prev_tag_close'] = '</li>';&nbsp; &nbsp; $config['next_link'] = 'Next';&nbsp; &nbsp; $config['next_tag_open'] = '<li>';&nbsp; &nbsp; $config['next_tag_close'] = '</li>';&nbsp; &nbsp; $this->pagination->initialize($config);

慕盖茨4494581

请检查官方分页文档:https : //www.codeigniter.com/user_guide/libraries/pagination.html#customizing-the-previous-link 这是示例。&nbsp; &nbsp; &nbsp; &nbsp; $config['base_url'] = base_url() . 'paging/custom';&nbsp; &nbsp; &nbsp; &nbsp; $config['total_rows'] = $total_records;&nbsp; &nbsp; &nbsp; &nbsp; $config['per_page'] = $limit_per_page;&nbsp; &nbsp; &nbsp; &nbsp; $config["uri_segment"] = 3;&nbsp; &nbsp; &nbsp; &nbsp; // custom paging configuration&nbsp; &nbsp; &nbsp; &nbsp; $config['num_links'] = 2;&nbsp; &nbsp; &nbsp; &nbsp; $config['use_page_numbers'] = TRUE;&nbsp; &nbsp; &nbsp; &nbsp; $config['reuse_query_string'] = TRUE;&nbsp; &nbsp; &nbsp; &nbsp; $config['full_tag_open'] = '<div class="pagination">';&nbsp; &nbsp; &nbsp; &nbsp; $config['full_tag_close'] = '</div>';&nbsp; &nbsp; &nbsp; &nbsp; $config['first_link'] = 'First Page';&nbsp; &nbsp; &nbsp; &nbsp; $config['first_tag_open'] = '<span class="firstlink">';&nbsp; &nbsp; &nbsp; &nbsp; $config['first_tag_close'] = '</span>';&nbsp; &nbsp; &nbsp; &nbsp; $config['last_link'] = 'Last Page';&nbsp; &nbsp; &nbsp; &nbsp; $config['last_tag_open'] = '<span class="lastlink">';&nbsp; &nbsp; &nbsp; &nbsp; $config['last_tag_close'] = '</span>';&nbsp; &nbsp; &nbsp; &nbsp; $config['next_link'] = 'Next Page';&nbsp; &nbsp; &nbsp; &nbsp; $config['next_tag_open'] = '<span class="nextlink">';&nbsp; &nbsp; &nbsp; &nbsp; $config['next_tag_close'] = '</span>';&nbsp; &nbsp; &nbsp; &nbsp; $config['prev_link'] = 'Prev Page';&nbsp; &nbsp; &nbsp; &nbsp; $config['prev_tag_open'] = '<span class="prevlink">';&nbsp; &nbsp; &nbsp; &nbsp; $config['prev_tag_close'] = '</span>';&nbsp; &nbsp; &nbsp; &nbsp; $config['cur_tag_open'] = '<span class="curlink">';&nbsp; &nbsp; &nbsp; &nbsp; $config['cur_tag_close'] = '</span>';&nbsp; &nbsp; &nbsp; &nbsp; $config['num_tag_open'] = '<span class="numlink">';&nbsp; &nbsp; &nbsp; &nbsp; $config['num_tag_close'] = '</span>';&nbsp; &nbsp; &nbsp; &nbsp; $this->pagination->initialize($config);&nbsp; &nbsp; &nbsp; &nbsp; // build paging links&nbsp; &nbsp; &nbsp; &nbsp; $params["links"] = $this->pagination->create_links();&nbsp; &nbsp; &nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP