[英]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'] = ' <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(' ',$str_links );
$this->load->view('admin/booking/index',$data);}
页面网址是http://127.0.0.1/admin/booking/1,它可以正常工作。
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
您的基本网址应类似于
| 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/';
如果您的网址中包含IP地址,则某些链接可能无法正常工作,这就是为什么最好设置网址并使用localhost而不是IP
还要确保按照ucfirst的方法来获取类和文件名,如此处https://www.codeigniter.com/user_guide/general/controllers.html#let-s-try-it-hello-world所述
您错过了配置。 将其放在配置中
$config['uri_segment'] = 3;
而不是此配置$config['use_page_numbers'] = TRUE;
并尝试
通过使用inspect-> element检查第二页重定向到的URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.