我是Codeigniter的新手,我正在進行分頁。但是我的代碼中有錯誤。在下面的代碼中我做了什麼錯誤? 我附上了我的代碼片段。分頁在Codeigniter中無法正常工作
路線
$route['default_controller'] = "pages";
$route['default_controller/(:num)'] = "pages/index/$1";
控制器
public function index($page='home')
{
if (! file_exists(APPPATH.'views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
$config=[
'base_url' => base_url().'/pages/index',
'per_page' => 5,
'total_rows' =>$this->products_model->record_count()
];
$this->pagination->initialize($config);
$data['title'] = ucfirst($page); // Capitalize the first letter
$data['products'] = $this->products_model->get_products($config['per_page'], $this->uri->segment(3));
$data['request'] = 'pages/home';
$this->load->view('templates/content',$data);
}
模型
public function get_products($limit, $offset)
{
$this->db->order_by('id', 'DESC');
$this->db->limit($limit, $offset);
$query=$this->db->get('product');
return $query->result_array();
}
public function record_count($value='')
{
return $this->db->count_all("product");
}
六ew
<?php echo $this->pagination->create_links() ?>
在視圖中,我顯示錶中的記錄。記錄顯示第一頁,但是當我點擊第二頁它顯示錯誤
"**404 Page Not Found**"
任何形式的關於此問題的幫助將得到高度讚賞。提前致謝。
您希望看到的記錄是什麼?是否有超過5個? – theUtherSide
是我有30多條記錄,但是當我點擊第二頁的分頁時,頁面沒有找到錯誤顯示 –
你可以發佈代碼也是你的按鈕?這可能是。或者,當您獲得404時,$ $ page的價值是多少?也許這個文件不存在。 – theUtherSide