Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODEL
- <?php if(!defined('BASEPATH')) exit('No direct script access allowed');
- class M_home extends CI_model{
- private $tbl_product ='product';
- var $tableProduct = 'product';
- var $tableCategory = 'category';
- function __construct(){
- parent::__construct();
- }
- function listProductPerCategory($id, $limit, $start){
- $this->db->select('
- category.id, category.category, product.id, product.id_category,
- product.name, product.picture, product.description, product.permalink, product.part_no
- ');
- $this->db->from('product');
- $this->db->join('category', 'product.id_category = category.id');
- $this->db->where('product.id_category', $id);
- $this->db->order_by('product.part_no','ASC');
- $this->db->limit($limit, $start);
- $query = $this->db->get();
- //$query = $this->db->get_where($this->tableCategory);
- return $query->result();
- }
- function listProductPerCategory_num_rows($id){
- $this->db->select('*');
- $this->db->from('product');
- $this->db->join('category', 'product.id_category = category.id');
- $this->db->where('product.id_category', $id);
- $data = $this->db->get();
- return $data->num_rows();
- }
- }
- ?>
- Controller
- <?php if(!defined('BASEPATH')) exit('No direct script access allowed');
- class Home extends CI_Controller{
- private $limitproduk=16;
- function __construct(){
- parent::__construct();
- $this->load->model('frontend/M_home', '', True);
- $this->load->helper('url');
- }
- function listcategory($page=null){
- $id = $this->input->get('list');
- $data['categoryHead'] = $this->M_home->listCategory();
- $this->load->view('frontend/template/header', $data);
- $data['productsLast'] = $this->M_home->listProductLast();
- $data['productsLast2'] = $this->M_home->listProductLast2();
- $data['category'] = $this->M_home->listCategory();
- $jumlah = $this->M_home->listProductPerCategory_num_rows($id);
- $config['base_url'] = base_url('categoryproduct'.'?'.http_build_query($_GET));
- $config['total_rows'] = $jumlah;
- $config['per_page'] = 12;
- $config['first_link'] = 'First';
- $config['last_link'] = 'Last';
- $config['next_link'] = 'Next';
- $config['prev_link'] = 'Prev';
- $config['page_query_string'] = TRUE;
- $dari = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
- $data['listCategory'] = $this->M_home->listProductPerCategory($id, $config['per_page'],$dari);
- $this->pagination->initialize($config);
- $this->load->view('frontend/category', $data);
- $this->load->view('frontend/template/footer');
- //end paging
- }
- }
- ?>
- VIEW
- <div class="middle-main"><!--features_items-->
- <?php $this->input->get('listCategory');?>
- <?php if(isset($listCategory)) : foreach ($listCategory as $row) :?>
- <div class="col-sm-4">
- <div class="product-image-wrapper">
- <div class="single-products">
- <div class="productinfo text-center">
- <?php if(!empty($row->picture)): ?>
- <img src="<?=site_url();?>template/backend/uploads/products/<?php echo $row->picture ;?>" height="180" alt="" />
- <?php else :?>
- <img alt="" src="http://placehold.it/50x35">
- <?php endif;?>
- <tr><h2><?php echo $row->category ;?></h2></tr>
- <tr><p><?php echo substr($row->name, 0, 100) ;?></p></tr>
- <p><?php echo $row->part_no;?></p>
- <tr><a href="<?= site_url("view")."?productdetail=".$row->id;?>" class="btn btn-default add-to-cart"><i class="fa fa-check"></i>Details</a></tr>
- </div>
- </div>
- </div>
- </div>
- <?php endforeach; ?>
- <?php endif; ?>
- </div><!--features_items-->
- <div class="pagination-area">
- <!-- <li><a href="" class="active">1</a></li>
- <li><a href="">2</a></li>
- <li><a href="">3</a></li>
- <li><a href=""><i class="fa fa-angle-double-right"></i></a></li> -->
- <?php echo $this->pagination->create_links(); ?>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement