我一直在努力完成这项工作,我希望在我的应用程序中进行分页。我现在只能数表中的行数。但当我点击下一批数据的链接时,我收到一个错误404。
这是下面的代码。这是我的控制器
public function index($page='dboard', $offset=0){
$config['base_url'] = base_url() . 'manager/cplfc/';
$config['total_rows'] = $this->db->count_all('users','attendance');
$config['per_page'] = 1;
$config['uri_segment'] = 1;
$config['attributes'] = array('class' => 'pagination');
// Init Pagination
$this->pagination->initialize($config);
$data['users'] = $this->ManagerModel->get_users(FALSE, $config['per_page'], $offset);
if(!file_exists(APPPATH.'views/controls/manager/'.$page.'.php')){show_404();}
$data['title']=ucfirst($page);
$this->load->view('controls/manager/header');
$this->load->view('controls/manager/'.$page,$data);
$this->load->view('controls/manager/footer');
}
这是型号
public function get_users($id = FALSE, $limit = FALSE, $offset = FALSE){
if($limit){
$this->db->limit($limit, $offset);
}
if($id === FALSE){
$this ->db->order_by('id', 'desc');
$query = $this->db->get('users');
return $query->result_array();
}
}
这是我的观点
<div class="pagination pagination-centered">
<ul><li><?php echo $this->pagination->create_links(); ?></li></ul>
</div>
我能做些什么来使它工作?提前感谢
分页函数自动确定URI的哪个段包含页码。如果你需要不同的东西,你可以指定它,它通常应该是$config['uri_segment'] = 3;
我只需要将URL Segment设置为";4〃;因为URL
$config = array();
$offset = $this->uri->segment(4);
$config['base_url'] = base_url() . 'manager/cplfc/';
$config['total_rows'] = $this->db->count_all('users','attendance');
$config['per_page'] = 1;
$config['uri_segment'] = 1;
$config['attributes'] = array('class' => 'pagination');