我是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