Hacksas

Model - Controller (pets)

Aug 28th, 2018
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.59 KB | None | 0 0
  1. Controller
  2. public function index(){
  3.  
  4.     $query = $this->db->get('pets');
  5.     $pet_num = $query->num_rows();
  6.  
  7.     $config = array();
  8.  
  9.     $config["base_url"] = base_url() . "pets/index/";
  10.     $config["total_rows"] = $pet_num;
  11.     $config["per_page"] = 12;
  12.     $config['use_page_numbers'] = TRUE;
  13.     $config['reuse_query_string'] = TRUE;
  14.  
  15.     $config['attributes'] = array('class' => 'page-link');
  16.     $config["full_tag_open"] = '<ul class="pagination">';
  17.     $config["full_tag_close"] = '</ul>';
  18.     $config["first_link"] = "&laquo;";
  19.     $config["first_tag_open"] = "<li>";
  20.     $config["first_tag_close"] = "</li>";
  21.     $config["last_link"] = "&raquo;";
  22.     $config["last_tag_open"] = "<li>";
  23.     $config["last_tag_close"] = "</li>";
  24.     $config['next_link'] = '&gt;';
  25.     $config['next_tag_open'] = '<li>';
  26.     $config['next_tag_close'] = '<li>';
  27.     $config['prev_link'] = '&lt;';
  28.     $config['prev_tag_open'] = '<li class="page-item">';
  29.     $config['prev_tag_close'] = '<li>';
  30.     $config['cur_tag_open'] = '<li class="page-item active"><a class="page-link" href="#">';
  31.     $config['cur_tag_close'] = '</a></li>';
  32.     $config['num_tag_open'] = '<li>';
  33.     $config['num_tag_close'] = '</li>';
  34.  
  35.     $this->pagination->initialize($config);
  36.  
  37.     $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 1;
  38.  
  39.     $limit = $config['per_page'];
  40.     $start = ( $page - 1 ) * $config['per_page'];
  41.  
  42.     $data['pets'] = $this->pet_model->get_filtered_pets($limit, $start);
  43.  
  44.     $data["links"] = $this->pagination->create_links();
  45.  
  46.     //View files
  47.     $this->load->view('templates/header', $data);
  48.     $this->load->view('pets/index', $data);
  49.     $this->load->view('templates/footer', $data);
  50.   }
  51.  
  52. //-----------------------------------------------------
  53.  
  54. Model
  55. public function get_filtered_pets($limit, $start){
  56.     $this->db->order_by('pet_id', 'DESC');
  57.     $this->db->join('users', 'users.user_id = pets.pet_user_id');
  58.     $this->db->join('pet_categories', 'pet_categories.pet_category_id = pets.category_id');
  59.  
  60.     $pet_data = array();
  61.     if ( $this->input->get('petStatus') ) {
  62.       $pet_data['pet_status'] = $this->input->get('petStatus');
  63.     }
  64.     if ( $this->input->get('petCategory') ) {
  65.       $pet_data['category_id'] = $this->input->get('petCategory');
  66.     }
  67.     if ( $this->input->get('petGender') ) {
  68.       $pet_data['pet_gender'] = $this->input->get('petGender');
  69.     }
  70.     if ( !empty($pet_data) ) {
  71.       $this->db->where($pet_data);
  72.     }
  73.    
  74.     $this->db->limit($limit, $start);
  75.     $query = $this->db->get('pets');
  76.  
  77.     return $query->result_array();
  78.  
  79.   }
Advertisement
Add Comment
Please, Sign In to add comment