[英]Getting 404 errors for codeigniter pagination
this is my class: 这是我的课:
class Pacients extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->library('email');
$this->load->library('session');
$this->load->library('pagination');
$this->load->model('pacient_model');
$this->load->model('department_model');
}
public function index(){
$id_doctor = $this->session->userdata('userid');
$department = $this->department_model->get_department_by_doctor($id_doctor); // get deparmentd_id
$diagnostics = $this->department_model->get_diagnostics($department[0]->department_id); // get diagnostics by using deparment id
$department_data = $this->department_model->get_department_by_id($department[0]->department_id); // get all info about deparment
//start pagination
if ($this->uri->segment(2) == null || $this->uri->segment(2) == ""){
$limit = 0;
}else{
$limit = $this->uri->segment(2);
}
$get_pacients = $this->pacient_model->get_pacients_by_doctor($id_doctor, $limit);
$total = $this->pacient_model->get_total_pacients_by_doctor($id_doctor);
$config['base_url'] = base_url().'pacients';
$config['total_rows'] = $total[0]->total;
$config['per_page'] = 3;
$this->pagination->initialize($config);
// end pagination
$data = array(
'pacients' => $get_pacients,
'diagnostics' => $diagnostics,
'department_data' => $department_data
);
if (!$diagnostics){// check if there any diagnostic in db associated to the current department
$data['error'] = 1;// if it is 1 then a form will apears in the view
}
$this->load->view('frontend/common/header');
$this->load->view('frontend/pacients',$data);
$this->load->view('frontend/common/footer');
}
}
In the get_pacients variable I have all of the results and I got all of the wanted results. 在get_pacients变量中,我得到了所有结果,并且得到了所有想要的结果。 in view in shows me the pagination.
鉴于显示给我分页。 but when i clicked on the page 2 it shows me the 404 page.
但是,当我单击第2页时,它显示了404页。 It is weird, on another page i used the same pagination implementation and it works.
很奇怪,在另一页上,我使用了相同的分页实现,并且可以正常工作。 The url looks like:
网址看起来像:
http://localhost/licenta/pacients
Do you have any idea why I get the 404 ? 你知道为什么我会收到404吗? I am using Codeigniter 3. Thx in advance
我正在使用Codeigniter 3。
In codeigniter by default 2nd segment of the URI is method of class. 默认情况下,在codeigniter中,URI的第二段是class的方法。 so you have to change your pagination variable to you have to make these changes.
因此,您必须更改分页变量才能进行这些更改。
$this->uri->segment(2);
to $this->uri->segment(3);
到
$this->uri->segment(3);
$config['base_url'] = base_url().'pacients/index';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.