简体   繁体   English

分页中的Codeigniter错误404

[英]Codeigniter Error 404 in pagination

I'm having problems when I try to access the next page what happens is that it shows an error 404 of codeigniter. 我在尝试访问下一页时遇到问题,发生的是它显示了Codeigniter错误404。 How do I fix this? 我该如何解决?

Controller 调节器

//START OF PAGINATION
    $this->load->library('pagination');
    $table = "entries";
    $config = array();
    $config["base_url"] = base_url() . "entries/";

        if(isset($_POST['event']) AND $_POST['event'] != "All"){
            $where = "event = '$_POST[event]' AND deleted = 0";
            $config["total_rows"] = $this -> entries_model -> count_filtered_entries($table,$where);
        }

        else{
        $config["total_rows"] = $this -> entries_model -> count_entries($table);
        }

    $config["per_page"] = 10;
    $config["uri_segment"] = 3;
    $this->pagination->initialize($config);
    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

    echo "PAGE NUMBER ".$page;

        if(isset($_POST['event']) AND $_POST['event'] != "All")
        {
            $where = "event = '$_POST[event]' AND deleted = 0";
            $data["records"] = $this -> entries_model -> select_filtered_entries($config["per_page"], $page, $where);
        }
        else
        {
            $data["records"] = $this -> entries_model -> select_entries($config["per_page"], $page);
        }

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

        $this->load->view('entries_index', $data);

Your pagination config 您的分页配置

$config["base_url"] = base_url() . "entries/";

and in your URI segemnt 并在您的URI段中

$config["uri_segment"] = 3;
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

Actually t here is only one URI segment , So change like this 实际上, 这里只是一个URI段 ,所以像这样更改

$config["uri_segment"] = 1;
$page = ($this->uri->segment(1)) ? $this->uri->segment(1) : 0;

Enable page_query_string 启用page_query_string

    $this->load->library('pagination'); 
    $config['base_url'] =base_url() . "entries?p=0";
    $config['total_rows'] = 100; 
    $config['per_page'] = 10;
    $config['page_query_string'] = TRUE;

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

Solved it by changing the base_url to $config["base_url"] = site_url('entries/index'); 通过将base_url更改为$config["base_url"] = site_url('entries/index'); Because my pagination is on the index of a controller. 因为我的分页在控制器的索引上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM