这是我的控制器代码。我对base_url感到困惑,不知道以下URL是写入还是错误。
Public function index(){
$this->load->library('pagination');
//setting value for pagination
$config['base_url'] = base_url()."/index.php/products/index";
$config['total_rows'] = $this->Product_model->record_count();
$config['per_page'] = 10;
$config['num_links'] = 20;
$this->pagination->initialize($config);
$data['products'] = $this->Product_model->get_products('productid','DESC', $config["per_page"], $this->uri->segment(3));
//Load View
$data['main_content'] = 'products';
$this->load->view('layouts/main', $data);
}
并查看代码
<div id="pagination">
<?php echo $this->pagination->create_links();?>
</div>
答案 0 :(得分:0)
用你的分页检查你的routes.php但是你的代码不多了 您没有显示获取产品的模型函数。
$route['products'] = "product/index"
$route['products/(:any)'] = "product/index/$1";
试试这个
public function index(){
// Load your model
$this->load->model('product_model');
// Load Pagination Library
$this->load->library('pagination');
// Uri segment would be 2
$config['base_url'] = base_url('products');
// Or
//Uri segment would be 2
// $config['base_url'] = base_url('index.php/products');
$config['total_rows'] = $this->db->count_all('products');
$config['per_page'] = 10;
$config['num_links'] = 20;
$config['page_query_string'] = TRUE;
$config['uri_segment'] = 2;
// If use bootstrap or else remove.
$config['full_tag_open'] = "<ul class='pagination'>";
$config['full_tag_close'] ="</ul>";
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tagl_close'] = "</li>";
$this->pagination->initialize($config);
// Removed DESC
$data['products'] = $this->product_model->get_products('productid', $config["per_page"], $config['uri_segment']);
$data['pagination'] = $this->pagination->create_links();
//Load View
$data['main_content'] = 'products';
$this->load->view('layouts/main', $data);
}
查看强>
<div id="pagination">
<?php echo $pagination;?>
</div>