Pagination links created with bootstrap class "pagination" are not working. Links created without adding bootstrap class working fine. Here is my controller Code
$config ['base_url'] = base_url () .'adv/index';
$config ['total_rows'] = $result->num_rows();
//$config ['uri_segment'] = $segment;
$config ['per_page'] = 5;
$config ['num_links'] = 5;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li class="page-item">';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="page-item prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<liclass="page-item">';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<liclass="page-item">';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="page-item active"><a href="page-link">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li class="page-item">';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$data['links']=$this->pagination->create_links();
$category=$this->adv_model->adv_get_paginated_data($segment,5);
$data['category']=$category;
$this->global['pageTitle'] = 'Media : Communiation';
$this->loadViews("adv_view", $this->global,$data, NULL);
[View Image][1]
[1]: https://i.stack.imgur.com/JDcVX.png
Related
`
Controller :
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$config = array();
$config['base_url'] = base_url().'tr_admin/billmanagement/';
$config['total_rows'] = $this->bill_model->count_all_bill($this->session->userdata('searchBillRec'));
$config['per_page'] = 100;
$config['use_page_numbers'] = TRUE;
$config["uri_segment"] = 3;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['use_page_numbers'] = FALSE;
$config['next_link'] = 'Next';
$config['next_tag_open'] = '<li class="next page">';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = ' Previous';
$config['prev_tag_open'] = '<li class="prev page">';
$config['prev_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li class="page">';
$config['num_tag_close'] = '</li>';
$data['recList'] = $this->bill_model->get_bill($config["per_page"],$page,$this->session->userdata('searchBillRec'));
$this->pagination->initialize($config);
$data['main_content'] = 'tr_admin/billmanagement';
$this->load->view('tr_admin/includes/template', $data);
Model:
if($filterData['bill_to']!=''){
$this->db->like('bill_to', $filterData['bill_to'],'both');
}
$this->db->order_by("bill_id","DESC");
$this->db->limit($per_page,$page);
return $this->db->get()->result_array();
`
Pagination links only show when there's more results than the current offset you set. So if there's only 5 records and your offset is 10 then there's no pagination to do.
I just trying to make pagination in CI, this is the error
Message: Object of class CI_DB_mysqli_result could not be converted to int
Message: Object of class CI_DB_mysqli_result could not be converted to number
this is my controller buku
{
$data['link_admin'] = 'active';
$config['base_url'] = base_url() . 'admin/buku/';
$config['total_rows'] = $this->model->get_table('tbl_buku');
$config['per_page'] = 10;
$config['first_tag_open'] = '<li class="page-item">';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li class="page-item">';
$config['last_tag_open'] = '</li>';
$config['full_tag_open'] = '<div class="pagination pagination-sm m-0 float-right">';
$config['full_tag_close'] = '</ul></div></div>';
$config['num_tag_open'] = '<li class="page-item">';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="page-item active"><a class="page-link" href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['next_link'] = '→';
$config['next_tag_open'] = '<li class="page-item">';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = '←';
$config['prev_tag_open'] = '<li class="page-item">';
$config['prev_tag_close'] = '</li>';
$this->pagination->initialize($config);
$data['offset'] = $this->uri->segment(3);
$data['query'] = $this->model->get_all_paginate_book('tbl_buku', 'id', $config['per_page'], $this->uri->segment(3));
$data['id'] = "KB".str_pad($config['total_rows']+1, 4 ,0,STR_PAD_LEFT);
$data['kategori'] = $this->model->get_table('tbl_kategori');
$data['title'] = "Data Buku | Perpustakaan";
$data['title2'] = "Data Buku";
$data['users'] = $this->db->get_where('users', ['email' => $this->session->userdata('email')])->row_array();
$this->load->view('templates/header', $data);
$this->load->view('templates/topsidebar', $data);
$this->load->view('admin/buku', $data);
}
this is the view code
I want to access pagination URL without query string in CodeIgniter like
http://127.0.0.1/hmvc/business_list/20
Now I am getting URL like
http://127.0.0.1/hmvc/business_list/?p=2
By this I am unable to read the URL segment and pagination is not working fine. It should return 0-10 records on the first page and 10-20 on second page and so on. But in my case, it returns 0-10 on the first page then 2-12 on the second page on the basis of URL segment.
Here is my code:
public function index()
{
$query = $this->db->get('categories','10',$this->uri->segment(2));
$data['results'] = $query->result();
$data['seg'] = $this->uri->segment(2);
$query2 = $this->db->get('categories');
$config['base_url'] = base_url().'business_list/';
$config['total_rows'] = $query2->num_rows();
$config['per_page'] = 10;
// $config['uri_segment'] = $this->uri->segment(2);
// $config['page_query_string'] = false;
$config['page_query_string'] = true;
$config['full_tag_open'] = "<ul class='pagination pagination-right margin-none'>";
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = '<li>';
$config['next_tagl_close'] = '</li>';
$config['prev_tag_open'] = '<li>';
$config['prev_tagl_close'] = '</li>';
$config['first_tag_open'] = '<li>';
$config['first_tagl_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tagl_close'] = '</li>';
$this->pagination->initialize($config);
$data['links'] = $this->pagination->create_links();
$data['title'] = "Business List";
$this->load->view('categories',$data);
}
How do I rectify this problem?
Use below configuration for pagination
$config['per_page'] = 10;
$config['uri_segment'] = 2;
$config['full_tag_open'] = '<ul class="pagination pagination-right margin-none">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class='disabled'><li class='active'><a href='#'>';
$config['cur_tag_close'] = '<span class='sr-only'></span></a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['enable_query_strings'] = TRUE;
I have url like this:
myproject/search?s=a
How to make pagination
Here my code in controller :
public function index()
{
$keyword = $this->input->get('s');
$config['per_page'] = 2;
$config['uri_segment'] = 2;
$config['full_tag_open'] = '<nav class="pagination"><ul>';
$config['full_tag_close'] = '</ul></nav>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="'.site_url(uri_string()).'">';
$config['cur_tag_close'] = '<span class="sr-only">(current)</span></a></li>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['first_link'] = '«';
$config['prev_link'] = '‹';
$config['last_link'] = '»';
$config['next_link'] = '›';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['base_url'] = site_url('search');
$config['total_rows'] = $this->m_home->count_search_produk($keyword);
$this->pagination->initialize($config);
$data['results'] = $this->m_home->search_produk($keyword, $config['per_page'], 0);
$data['pagination'] = $this->pagination->create_links();
$data['total'] = $this->m_home->count_search_produk($keyword);
$this->theme->frontend('f_home/search', $data);
}
in this line :
$data['results'] = $this->m_home->search_produk($keyword, $config['per_page'], 0);
I set offset 0, I want to set dinamicly, using uri_segment, but not work, how to do that?
when I click pagination, the url like this:
myproject/search?s=a&page=3
Its working very well
public function search()
{
$keyword = $this->input->get('s');
$data['title'] = 'Search Results';
$config['per_page'] = 2;
$config['uri_segment'] = 2;
$config['full_tag_open'] = '<nav class="pagination"><ul>';
$config['full_tag_close'] = '</ul></nav>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="'.site_url(uri_string()).'">';
$config['cur_tag_close'] = '<span class="sr-only">(current)</span></a></li>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['first_link'] = '«';
$config['prev_link'] = '‹';
$config['last_link'] = '»';
$config['next_link'] = '›';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['page_query_string'] = TRUE;
$config['query_string_segment']= 'page';
$config['base_url'] = site_url('search?s='.$keyword);
$config['total_rows'] = $this->m_home->count_search_produk($keyword);
$this->pagination->initialize($config);
$page = (empty($_GET['page'])) ? 0 : $_GET['page'];
$data['results'] = $this->m_home->search_produk($keyword, $config['per_page'], $page);
$data['pagination'] = $this->pagination->create_links();
$data['total'] = $this->m_home->count_search_produk($keyword);
$this->theme->frontend('f_home/search', $data);
}
I'm doing pagination using Codeigniter pagination class. My current config variable is:
$config['base_url'] = base_url('admin/sub_categories');
$config['total_rows'] = $this->sub_categories_model->get_count();
$config['base_url'] = "";
$config['total_rows'] = "";
$config['per_page'] = 30;
$config['first_link'] = 'Эхнийх';
$config['last_link'] = 'Сүүлийх';
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
Then using it on every controller was using too many lines. So I created pagination.php under config/ folder. Then put above codes. Then loaded it like:
$this->config->load('pagination', TRUE);
$this->pagination->initialize($this->config->item('pagination'));
Now you see, my problem is $config['base_url'] and $config['total_rows'] can be different on every controllers. How can I change their value after load?
If I understand you, then you may try this:
$this->config->load('pagination', TRUE);
$conf = $this->config->item('pagination');
$conf['base_url'] = base_url('admin/sub_categories');
$conf['total_rows'] = $this->sub_categories_model->get_count();
$this->pagination->initialize($conf);
You should do it at every controller you want to use paginator with diferent values for base_url and total_rows