为 codeigniter 分页获取 404 错误

Getting 404 errors for codeigniter pagination

这是我的 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');
    } 
}

在 get_pacients 变量中我有所有的结果,我得到了所有想要的结果。在视图中向我展示了分页。但是当我点击第 2 页时,它显示了 404 页面。很奇怪,在另一个页面上我使用了相同的分页实现并且它有效。 url 看起来像:

http://localhost/licenta/pacients  

你知道我为什么收到 404 吗?我正在使用 Codeigniter 3。提前致谢

默认情况下,在 codeigniter 中,URI 的第二段是 class 的方法。因此您必须将分页变量更改为必须进行这些更改。

$this->uri->segment(2);$this->uri->segment(3);

$config['base_url'] = base_url().'pacients/index';