我尝试使用codeigniter中的bootstrap进行分页。在我看来,分页显示。但是,当我想去其他页面时,我找到了404页面未找到您找不到的页面。怎么了?
这是我的控制器
public function shop($page = 'shop', $offset = 0) {
$data['title'] = ucfirst($page);
// breadcrumb start
$breadcrumb = array(
"Beranda" => "index",
"Belanja Sekarang" => "",
);
$data['breadcrumb'] = $breadcrumb;
// breadcrumb end
// pagination start
$jml = $this->db->get('produk');
$num_rows = $this->db->count_all("produk");
$config['base_url'] = base_url() . "page/shop";
$config['total_rows'] = $num_rows;
$config['per_page'] = 9;
$config['uri_segment'] = 2;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['offset'] = $offset;
$page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
$offset = $page == 0 ? 0 : ($page - 1) * $config["per_page"];
// memanggil method di model
$data['produk'] = $this->cart_model->retrieve_products($config['per_page'], $page);
$this->load->view('user/templates/header', $data);
$this->load->view('user/templates/navigation', $data);
$this->load->view('user/pages/' . $page, $data);
$this->load->view('user/templates/footer', $data);
}
这是我的模特
class Cart_model extends CI_Model {
// Our Cart_model class extends the Model class
// Function to retrieve an array with all product information
function retrieve_products($num, $offset) {
$query = $this->db->get('produk', $num, $offset); // Select the table products
return $query->result_array(); // Return the results in a array.
}
}
答案 0 :(得分:0)
网址错误:
那个网址是: http://localhost/sjpro/page/shop&=9
true: http://localhost/sjpro/page/shop/9
来自职能
public function shop($page = 'shop', $offset = 0)
答案 1 :(得分:0)
$config['base_url'] = base_url() . "page/shop";
$config['total_rows'] = $num_rows;
$config['per_page'] = 9;
$config['uri_segment'] = 2;
$limit = $config['per_page'];
// boostrap Pagination. Just import boostrap. This will take CSS code automatically
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
$data['links'] = $this->pagination->create_links();
$data['produk'] = $this->cart_model->retrieve_products($limit, $page);
$this->load->view('user/templates/header', $data);
$this->load->view('user/templates/navigation', $data);
$this->load->view('user/pages'. $data);
$this->load->view('user/templates/footer', $data);
模型中的
class Cart_model extends CI_Model
{
public function retrieve_products($limit , $page)
{
$query = $this->db->query("SELECT * FROM produk LIMIT $page,$limit ");
$result = $query->result_array();
return $result;
}
}
视野
foreach ( $produk as $new_produk )
{
//This should be your data base fields
echo $new_produk['database field1'];
echo $new_produk['database field2'];
}
<?$php
echo $links;//This create your pagination.
?>