我有有效的分页。我已将限制设置为每页 5 条记录,但我希望用户能够根据需要进行更改。问题是我不知道该怎么做。
在视图中,我创建了下拉菜单,因此用户可以选择每页要查看多少条记录:
<ul class="dropdown-menu">
<li>
<a href="<?php echo base_url(); ?>backOfficeUsers/displayAllUsers" id="2" class="pPage" data-tableid="smpl_tbl">
2 records per page
</a>
</li>
<li>
<a href="<?php echo base_url(); ?>backOfficeUsers/displayAllUsers" id ="50" class="pPage" data-tableid="smpl_tbl">
50 records per page
</a>
</li>
<li><a href="<?php echo base_url(); ?>backOfficeUsers/displayAllUsers" id="100" class="pPage" data-tableid="smpl_tbl">
100 records per page
</a>
</li>
<li>
<a href="<?php echo base_url(); ?>backOfficeUsers/displayAllUsers" id="all" class="pPage" data-tableid="smpl_tbl">
Display all records
</a>
</li>
</ul>
在我的控制器中,我有以下代码:
public function displayAllUsers()
{
$recordsPerPage = 5;
$limit = $recordsPerPage;
$offset = 3;
$offset = $this->uri->segment(3);
$this->db->limit($limit, $offset);
$data['users'] = $this->backOfficeUsersModel->get();
$totalresults = $this->db->get('back_office_users')->num_rows();
//initializing & configuring paging
$this->load->library('pagination');
$config['base_url'] = site_url('/backOfficeUsers/displayAllUsers');
$config['total_rows'] = $totalresults;
$config['per_page'] = $limit;
$config['uri_segment'] = 3;
$config['full_tag_open'] = '<div class="dataTables_paginate paging_bootstrap pagination"><ul>';
$config['full_tag_close'] = '</ul></div>';
$config['cur_tag_open'] = '<li><a href=# style="color:#ffffff; background-color:#258BB5;">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$data['main_content'] = 'bousers/users';
$data['title'] = 'Back Office Users';
$errorMessage = FALSE;
$this->load->vars($data,$errorMessage);
$this->load->vars($currentUser);
$this->load->view('backOffice/template');
} // end of function displayAllUsers
谁能告诉我如何显示用户从下拉菜单中选择的记录数?如果他没有选择任何东西,我想默认显示5条记录。
任何帮助将不胜感激。
问候,佐兰