大家好我是一个新的codeigniter我在codeigniter上有分页的问题我尝试搜索google和youtube但是我不能帮助我的人 这是我的代码模型:
<?php
class Product_model extends CI_Model {
function get_product($category="") {
$this->db->select('*');
$this->db->from('product');
if($category) {
$this->db->where('category',$category);
}
$query = $this->db->get();
return $query->result();
}
function get_total($category="") {
$this->db->select('count(*) AS num_row');
$this->db->from('product');
if($category) {
$this->db->where('category',$category);
}
$this->db->limit(1);
$query = $this->db->get();
return $query->row()->num_row;
}
}
这是我的控制器代码:
public function __construct()
{
parent::__construct();
$this->load->model('product_model','product');
}
public function menu()
{
$data = array();
$data['burger'] = $this->product->get_product('burger');
$total_burger = $this->product->get_total('burger');
$limit_burger = 1;
$link_burger = 'http://localhost/mbl/site/menu/burger';
$data['pagination_burger'] = $this->pagination($total_burger,$limit_burger,$link_burger);
$this->load->view('header_view');
$this->load->view('nav_view');
$this->load->view('content_view');
$this->load->view('content_left_view',$data);
$this->load->view('content_right_view');
$this->load->view('footer_view');
}
private function pagination($total ,$per_page ,$link) {
$config['base_url'] = $link;
$config['total_rows'] = $total;
$config['per_page'] = $per_page;
$config['page_query_string'] = TRUE;
$this->pagination->initialize($config);
return $this->pagination->create_links();
}
和我的观点:
<h1>Burger</h1>
<ul>
<?php foreach($burger as $val) { ?>
<li><?php echo $val->title; ?></li>
<?php } ?>
</ul>
<?php echo $pagination_burger; ?>