如何显示带有产品类别代码点火器的分页? [英] How to show pagination with product category codeigniter?
本文介绍了如何显示带有产品类别代码点火器的分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我是新的Codeigniter,我对Codeigniter的分页有问题,我尝试搜索google和youtube,但我做不到,谁可以帮我 这是我的代码模型:
Hi all I am a new of codeigniter I have problam with pagination on codeigniter I try to search google and youtube but I can not do it who can help me please this my code model:
<?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; ?>
推荐答案
在Codigniter中,它非常简单
In Codigniter it is very simple
$this->load->library('pagination');
加载该库
$config['base_url'] = 'http://example.com/index.php/test/page/';
$config['total_rows'] = 200;
$config['per_page'] = 20;
$this->pagination->initialize($config);
echo $this->pagination->create_links();
或
这篇关于如何显示带有产品类别代码点火器的分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文