Codeigniter分页下一页404未找到


codeigniter pagination next page 404 not found

索引页工作良好,但当我点击第2页时显示404页未找到

控制器

public function index() {
   $config = array();
   $config['base_url'] = base_url('admin/booking');
   $total_row = $this->booking_m->record_count();
   $config["total_rows"] = $total_row;
   $config["per_page"] = 1;
   $config['use_page_numbers'] = TRUE;
   $config['num_links'] = $total_row;
   $config['cur_tag_open'] = '&nbsp;<a class="current">';
   $config['cur_tag_close'] = '</a>';
   $config['next_link'] = 'Next';
   $config['prev_link'] = 'Previous';
   $this->pagination->initialize($config);
   if($this->uri->segment(3)){
     $page = ($this->uri->segment(3)) ;
  }
  else{
    $page = 1;
 }

  $data["info"] = $this->booking_m->fetch_data($config["per_page"], $page);
  $str_links = $this->pagination->create_links();
  $data["links"] = explode('&nbsp;',$str_links );

  $this->load->view('admin/booking/index',$data);}

网页网址是http://127.0.0.1/admin/booking/1 it work.

http://127.0.0.1/admin/booking/2//没有找到错误

模型
public function fetch_data($limit, $id) {
$this->db->limit($limit);
$this->db->where('id', $id);
$query = $this->db->get("booking");
if ($query->num_rows() > 0) {
    foreach ($query->result() as $row) {
    $data[] = $row;
    }
    return $data;
}
return false;
}

如果没有设置路由,请尝试

$route['admin/booking/(:any)'] = 'controllername/function/$1';
https://www.codeigniter.com/user_guide/general/routing.html?highlight=routes

你的基础url应该看起来像

| http://example.com/
|
| WARNING: You MUST set this value!
|
| If it is not set, then CodeIgniter will try guess the protocol and path
| your installation, but due to security concerns the hostname will be set
| to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise.
| The auto-detection mechanism exists only for convenience during
| development and MUST NOT be used in production!
$config['base_url'] = 'http://localhost/yourproject/';

如果你在url中有IP地址,那么一些链接可能无法工作,为什么最好设置url并使用localhost而不是IP

还要确保按照ucfirst方式命名类和文件名,如下所示https://www.codeigniter.com/user_guide/general/controllers.html#let-s-try-it-hello-world

您缺少一个配置。将其放在config

$config['uri_segment'] = 3;

而不是这个配置$config['use_page_numbers'] = TRUE;,并尝试

通过使用inspect->元素检查第二个页面要重定向到的url .