2015-10-27 41 views
1

大家好我是新笨的我有分頁對笨我嘗試搜索谷歌和YouTube,但我不能這樣做pro​​blam誰可以幫我請 這是我的代碼模型:如何使用產品類別codeigniter顯示分頁?

<?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; 
    } 

} 

這我controoler代碼:

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; ?> 
+0

閱讀本教程http://w3code.in/2015/10/how-to-do-pagination-in -codeigniter/ – Ricky

+0

我閱讀。但你可以編輯我的代碼? – He7nG

回答

0

在Codigniter它是非常簡單

$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(); 

check this url

+0

這兩個文件CI2和CI3現在在這裏http://www.codeigniter.com/docs – user4419336

+0

確定thz,但你可以編輯我的代碼? – He7nG

相關問題