Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Controller
- public function index(){
- $query = $this->db->get('pets');
- $pet_num = $query->num_rows();
- $config = array();
- $config["base_url"] = base_url() . "pets/index/";
- $config["total_rows"] = $pet_num;
- $config["per_page"] = 12;
- $config['use_page_numbers'] = TRUE;
- $config['reuse_query_string'] = TRUE;
- $config['attributes'] = array('class' => 'page-link');
- $config["full_tag_open"] = '<ul class="pagination">';
- $config["full_tag_close"] = '</ul>';
- $config["first_link"] = "«";
- $config["first_tag_open"] = "<li>";
- $config["first_tag_close"] = "</li>";
- $config["last_link"] = "»";
- $config["last_tag_open"] = "<li>";
- $config["last_tag_close"] = "</li>";
- $config['next_link'] = '>';
- $config['next_tag_open'] = '<li>';
- $config['next_tag_close'] = '<li>';
- $config['prev_link'] = '<';
- $config['prev_tag_open'] = '<li class="page-item">';
- $config['prev_tag_close'] = '<li>';
- $config['cur_tag_open'] = '<li class="page-item active"><a class="page-link" href="#">';
- $config['cur_tag_close'] = '</a></li>';
- $config['num_tag_open'] = '<li>';
- $config['num_tag_close'] = '</li>';
- $this->pagination->initialize($config);
- $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 1;
- $limit = $config['per_page'];
- $start = ( $page - 1 ) * $config['per_page'];
- $data['pets'] = $this->pet_model->get_filtered_pets($limit, $start);
- $data["links"] = $this->pagination->create_links();
- //View files
- $this->load->view('templates/header', $data);
- $this->load->view('pets/index', $data);
- $this->load->view('templates/footer', $data);
- }
- //-----------------------------------------------------
- Model
- public function get_filtered_pets($limit, $start){
- $this->db->order_by('pet_id', 'DESC');
- $this->db->join('users', 'users.user_id = pets.pet_user_id');
- $this->db->join('pet_categories', 'pet_categories.pet_category_id = pets.category_id');
- $pet_data = array();
- if ( $this->input->get('petStatus') ) {
- $pet_data['pet_status'] = $this->input->get('petStatus');
- }
- if ( $this->input->get('petCategory') ) {
- $pet_data['category_id'] = $this->input->get('petCategory');
- }
- if ( $this->input->get('petGender') ) {
- $pet_data['pet_gender'] = $this->input->get('petGender');
- }
- if ( !empty($pet_data) ) {
- $this->db->where($pet_data);
- }
- $this->db->limit($limit, $start);
- $query = $this->db->get('pets');
- return $query->result_array();
- }
Advertisement
Add Comment
Please, Sign In to add comment