Everything with this code is perfect, when I go to second or third ..etc pages
I can browse them normally, my issue with first page when I want to browse first page ,
it gives me this url (http://www.example.com/almanara-shipping/index.php/dashboard/search/)??
it should give me this url (http://www.example.com/almanara-shipping/index.php/dashboard/search?keyword=ali)
public function search($page_start = 0){
$this->load->model('Customers');
$keyword = $this->input->get('keyword');
$data['customers'] = $this->Customers->search($keyword ,2,$page_start);
$this->load->library('pagination');
$config['suffix'] = '?keyword='.$keyword;
$config['base_url'] = site_url()."/dashboard/search/";
$config['total_rows'] = $this->Customers->search_count($keyword);
$config['per_page'] = 2;
$config['full_tag_open'] = "<ul class='pagination'>";
$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['pages'] = $this->pagination->create_links();
$this->load->view('customers',$data);
$this->load->view('templates/footer');
}
I solved the issue by using this code below
$config['first_url'] = $config['base_url'].'?'.http_build_query($_GET);
Related
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
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 have a problem when i do search the pagination number still remains in the url result to showing no resuts. for example when i click a pagination link my url looks like this example/index.php/example/info/10 then when i do search, the url now the url looks like this example/index.php/example/info/10?search=word
How can i fixed this problem
Controller
public function info($offset=0)
{
$this->load->library('pagination');
$search = $this->input->get('search');
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
if($this->input->get('search')){
$count = $this->ticketing_mdl->count_all_ticket();
$config['total_rows'] = $count;
$config['suffix'] = '?' . http_build_query($_GET, '', "&");
$config['base_url'] = "/ticketing/index.php/ticketing/info";
$config['first_url'] = "/ticketing/index.php/ticketing/info?search=$search";
}else{
$this->db->where('is_valid','1');
$config['total_rows'] = $this->db->count_all_results('db_ticketing.tr_ticket');
$config['base_url'] = "/ticketing/index.php/ticketing/info";
}
$limit = 10;
$config['per_page'] = $limit;
$config['num_links'] = $limit;
$config['full_tag_open'] = '<div><ul class="pagination pagination-centered">';
$config['full_tag_close'] = '</ul></div>';
$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>";
$config['first_link'] = 'First';
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['ticket_list'] = $this->ticketing_mdl->get_all_ticket($limit,$page, $offset);
$this->load->view('ticketing/header');
$this->load->view('ticketing/left_menu');
$this->load->view('ticketing/info',$data);
}
Let me know if i am right.
I think you can control it by defining routes.
Set your $config['base_url'] of pagination library like example/index.php/search and define routes (application/config/routes.php) like
$route['search'] = "example/info";
$route['search/(:num)'] = "example/info/$1";
comment this $config['first_url'] = "/ticketing/index.php/ticketing/info?search=$search";
And dont forget to set the html form action="echo site_url('search');" method="get"
I hope this will give you some help.
I'm creating a pagination using codeigniter.
I want the link to be: site_name/categorie_name/page/id => id is dynamic.
When i create the pagination and when i'm on the page site_name/categorie_name/page/1. the next page link is replaced by site_name/categorie_name/page/1/id.
what should i do?
public function Pagginations($total_row,$baseurl,$per_page) {
$config = array();
$config["base_url"] = $baseurl;
$config["total_rows"] = $total_row;
$config["per_page"] = $per_page;
$config['use_page_numbers'] = TRUE;
//$config['num_links'] = 100;
$config['uri_segment'] = 2 ;
$config['num_links'] = 100;
$config['full_tag_open'] = "<ul class='pagination'>";
$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);
if ($this->uri->segment(2)) {
$config['page']= $page = ($this->uri->segment(2));
} else {
$config['page']= $page = 1;
}
$config["links"]=explode(' ', $this->pagination->create_links());
return $config;
}
18 is display of product on one row
$config = $this->Pagginations($total_row,$baseurl,18);