简体   繁体   中英

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. 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

$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

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

Enable 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'); Because my pagination is on the index of a controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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