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
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;
currently i am using this code for pagination in Codigniter
$config['base_url'] = SITEURL. 'search?qry='.$qry.'&';
$config['use_page_numbers'] = TRUE;
$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>';
$config['total_rows'] = $total_rows;
$config['per_page'] = RECORD_PER_PAGE;
$config['first_url'] = $config['base_url'] . '1' . http_build_query($_GET);
$config['num_links'] = 5;
From what I saw, CodeIgniter's pagination is counting the page wrong way. because I want pagination looking like this:
http://my-url.com/search?qry=abc&page=2
If you don't want to use the noraml uri string gived from CI and you want to use query string (site.com?var1=data&var2=xxx)
you need to change the application/config/config.php file setting the line
158 $config['enable_query_strings'] = FALSE; to TRUE
in your controller to make the pagination get the variables using the normal form
$var1 = $this->input->get('c');
$var2 = $this->input->get('m');
$var3 = $this->input->get('d');
I have a problem with pagination in CodeIgniter 2.x
This is my code in Controller:
$config['base_url'] = base_url().'crawl/all/'.$file.'/';
$config['total_rows'] = $total;
$config['per_page'] = 10;
$config['num_links'] = 3;
$config['uri_segment'] = 4;
$config['full_tag_open'] = '<ul id="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_tag_open'] = '<li class="next">';
$config['next_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active">';
$config['cur_tag_close'] = '</li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$data['total'] = $total;
$data['path'] = $this->path.'/'.$file;
$data['file'] = $file;
$data['batch'] = $this->batch->all($file, $config['per_page'], $config['uri_segment']);
and my view is just: <?php echo $this->pagination->create_links() ?>
The links for pages numbers work (they move from 1 to 2 etc), but the data does not display correctly.
You are missed out the page id because when you clicks on the page the page no has to send as query string and it has to add for the config.
Example code:
$limit = $this->config->item('paging_limit');
$offset = $id * $limit;
$data['rows'] = $this->news_model->get_moreNews($limit, $offset);
$config["image_url"]=$this->config->item("base_url");
$config['base_url'] = base_url().'/news/morenews/';
$config['total_rows'] = $this->db->count_all('news');
$config['per_page'] = $limit;
$config['chapter'] = $this->input->post('chapter');
$config['page'] = $id;
$this->paginationsimple->initialize($config);
$paginator=$this->paginationsimple->create_links();
$data['paginator'] = $paginator;
I'm using CI's pagination library. Here's my config:
$this->load->library('pagination');
$config = array();
$config['base_url'] = 'http://localhost/index.php/search/';
$config['total_rows'] = 200;
$config['per_page'] = 10;
$config['num_links'] = 4;
$config['full_tag_open'] = '<ol>';
$config['full_tag_close'] = '</ol>';
$config['first_link'] = 'First';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_link'] = 'Last';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['next_link'] = 'Next';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = 'Previous';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active">';
$config['cur_tag_close'] = '</li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
echo htmlentities($this->pagination->create_links());
echo ($this->pagination->create_links());
The resulting links has per_page twice, such as yo see here:
http://localhost/index.php/search/&per_page=&per_page=10. Any ideas why?
You are echoing it two times in the two last lines of the code
Replace:
echo htmlentities($this->pagination->create_links());
echo ($this->pagination->create_links());
To:
echo $this->pagination->create_links();
And you should pass your variables to the views instead of echoing it from the controller.