简体   繁体   English

找不到codeigniter分页404

[英]codeigniter pagination next page 404 not found

Index page are working well but when i click page 2 it show 404 page not found. 索引页运行良好,但是当我单击第2页时,显示找不到404页。

Controller 控制者

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);}

Page url is http://127.0.0.1/admin/booking/1 it work. 页面网址是http://127.0.0.1/admin/booking/1,它可以正常工作。

http://127.0.0.1/admin/booking/2 // Not found error http://127.0.0.1/admin/booking/2 //找不到错误

Model 模型

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;
}

Have you set the route if not try 如果没有尝试,您是否设定了路线

$route['admin/booking/(:any)'] = 'controllername/function/$1';

https://www.codeigniter.com/user_guide/general/routing.html?highlight=routes https://www.codeigniter.com/user_guide/general/routing.html?highlight=routes

Your base url should look something like 您的基本网址应类似于

| 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/';

If you have the IP address in your url then some links may not work that why is good to set url and use localhost instead of IP 如果您的网址中包含IP地址,则某些链接可能无法正常工作,这就是为什么最好设置网址并使用localhost而不是IP

Also make sure you follow the ucfirst way for class and file names as explained here https://www.codeigniter.com/user_guide/general/controllers.html#let-s-try-it-hello-world 还要确保按照ucfirst的方法来获取类和文件名,如此处https://www.codeigniter.com/user_guide/general/controllers.html#let-s-try-it-hello-world所述

You have missed a config. 您错过了配置。 Place it in config 将其放在配置中

$config['uri_segment'] = 3;

instead of this config $config['use_page_numbers'] = TRUE; 而不是此配置$config['use_page_numbers'] = TRUE; and try 并尝试

通过使用inspect-> element检查第二页重定向到的URL。

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

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