Cannot access protected property `CI_Pagination
Trying to add submit button on last page of pagination currently it's on every page by default...on line 49 i have condition to check whether i am in last page or not, I want a submit button at the end of the pagination page
Code on which error is showing..please explain how to implement
if($this->pagination->cur_page >= ceil($this->pagination->total_rows / $this->pagination->per_page))
{
$isLastPage = true;
}else{
$isLastPage = false;
}
Pagination code
public function quizdisplay()
{
//echo $this->pagination->create_links();
//$this->load->library('pagination');
$config = array();
$config['base_url'] = 'http://localhost/xampp/cii/index.php/Questions/quizdisplay';
//$config['total_rows'] = 10;
$total_row = $this->quizmodel->record_count();
$config["total_rows"] = $total_row;
$config['per_page'] = 1;
$config["uri_segment"] = 3;
$config['use_page_numbers'] = TRUE;
$config['num_links'] = $total_row;
$config['cur_tag_open'] = ' <a class="current">';
$config['cur_tag_close'] = '</a>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$this->pagination->initialize($config);
if($this->uri->segment(3)){
$page = ($this->uri->segment(3)) ;
}else{
$page = 1;
}
$data["results"] = $this->quizmodel->getQuestions($config["per_page"], $page);
$this->pagination->create_links();
$data["links"] = $this->pagination->create_links();
View data according to array.
$this->load->view("play_quiz", $data);
}
Both the codes are in same function
Related
I using GET method for searching records. now when i have applied pagination i can't understand how to submit data to next pagination page link.
I have tried this answer. but it is just stacking page number in link segments.
example:
From
localhost/phc/search/results/0?s=ai&product_cat=all&post_type=product
To
localhost/phc/search/results/?s=ai&product_cat=all&post_type=product/12/24
so i didn't used that code.
And now my code is:
public function results() {
//pagination
$offset = $this->uri->segment(3);
$limit = 12;
//$offset = 0;
$data['limit'] = $limit;
$config['base_url'] = base_url() . 'search/results/';
$config['first_url'] = base_url() .'search/results/0';
$data['total'] = $this->All_data_model->countSearchProducts($_GET);
$config['total_rows'] = $data['total'];
$config['per_page'] = $limit;
$config['uri_segment'] = 3;
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['offset'] = $offset;
$data['total_rows'] = $config['total_rows'];
$data['page'] = 'search';
$data['navbar'] = $this->All_data_model->navbarContent();
$data['products'] = $this->All_data_model->searchResults($_GET , $offset , $limit);
$this->template->write_view('content', 'products/search', $data);
$this->template->render();
}
Tell what the best way to submit data in this case if not GET and how can i access this data.
Put offset in your url
localhost/phc/search/results?s=ai&product_cat=all&post_type=product&offset=123
and set these configs.
$config['page_query_string'] = TRUE;
$config['query_string_segment'] = 'offset';
$config['reuse_query_string'] = TRUE;
I changed your code but it's not tested at all.
public function results() {
//pagination
$offset = $this->input->get('offset') ? $this->input->get('offset') : 0;
$limit = 12;
$data['limit'] = $limit;
$config['base_url'] = base_url() . 'search/results/';
$data['total'] = $this->All_data_model->countSearchProducts($_GET);
$config['total_rows'] = $data['total'];
$config['per_page'] = $limit;
// set these mostly...
$config['page_query_string'] = TRUE;
$config['query_string_segment'] = 'offset';
$config['reuse_query_string'] = TRUE;
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['offset'] = $offset;
$data['total_rows'] = $config['total_rows'];
$data['page'] = 'search';
$data['navbar'] = $this->All_data_model->navbarContent();
$data['products'] = $this->All_data_model->searchResults($_GET , $offset , $limit);
$this->template->write_view('content', 'products/search', $data);
$this->template->render();
}
The following piece of code for my pagination function like following:-
public function news()
{
$this->load->library('pagination');
$config = array();
$config["base_url"] = base_url() . "index.php/welcome/news";
$this->load->model('news_model');
$total_row = $this->news_model->record_count();
$config["total_rows"] = $total_row;
$config["per_page"] = 1;
$config['use_page_numbers'] = TRUE;
$config['num_links'] = $total_row;
$config['cur_tag_open'] = ' <a class="current">';
$config['cur_tag_close'] = '</a>';
$config['page_query_string'] = TRUE;
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$config['first_url'] = $config['base_url'].'?'.http_build_query($_GET);
$this->pagination->initialize($config);
if($this->uri->segment(3)){
$page = ($this->uri->segment(3)) ;
}
else{
$page = 1;
} //echo $config["per_page"].'/'.$page; exit();
$this->load->model('news_model');
$data["results"] = $this->news_model->fetch_data($config["per_page"], $page);
$str_links = $this->pagination->create_links();
$data["links"] = explode(' ',$str_links );
$this->load->model('news_model');
$data['lt_news'] = $this->news_model->get_lt_newsletter();
$data['rm_news'] = $this->news_model->get_rm_newsletter();
$this->load->view('newsletter/newsletter',$data);
}
From the above code, the url browser shows like the following:-
http://localhost/ins/index.php/welcome/news?per_page=2
I am like jammed as to how to change it to be look like the following:
http://localhost/ins/index.php/welcome/news/2
Is there a way to do it..? I am newbie to the pagination in codeigniter so, i do not know if there is a necessity to change the url parameters to be looking like the above..?
Set $config['page_query_string'] to false.
From the doc https://www.codeigniter.com/userguide3/libraries/pagination.html#customizing-the-pagination:
By default, the pagination library assume you are using URI Segments,
and constructs your links something like:
http://example.com/index.php/test/page/20 If you have
$config['enable_query_strings'] set to TRUE your links will
automatically be re-written using Query Strings. This option can also
be explicitly set. Using $config['page_query_string'] set to TRUE, the
pagination link will become:
http://example.com/index.php?c=test&m=page&per_page=20
Make the page a parameter of the function, like so:
public function news($pageNum)
{
...
$page = $pageNum
...
}
Then you should be able to access it via:
http://localhost/ins/index.php/welcome/news/2
Hi have am new to codeigniter and have been struggling with CI pagination library for days.
I have this app where all pagination are working fine except for skipping data by offset.
i.e. when I click on next, It only shifts data by 1 record only. Example: From 1-10 showing it goes to 2-11 and so on..
Here is my controller:
$active = 1;
$total = $this->all_users_model->total_number_of_rows();
$per_page = 10;
$offset = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$config['base_url'] = base_url().'admin/manage-users/';
$config['total_rows'] = $total;
$config['per_page'] = $per_page;
$config['use_page_numbers'] = TRUE;
$config['num_links'] = $total;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$config['first_link'] = 'First';
$config['prev_link'] = 'Previous';
$config['next_link'] = 'Next';
$config['last_link'] = 'Last';
$this->pagination->initialize($config);
$data['admin_all_users'] = $this->all_users_model->show_all_user_details($active, $per_page, $offset);
Model:
public function show_all_user_details($active,$per_page,$offset) {
$this->db->where(array('activated'=>$active,'admin !='=>1));
$this->db->limit($per_page,$offset);
$this->db->order_by('api_id','desc');
$query=$this->db->get('registered_members');
return $query->result();
}
It's because your offset is incrementing only with one at a time: page/1, page/2, also as your db query limit. Currently, your db limit is $this->db->limit(10, 1);, $this->db->limit(10, 2);.
This shows 10 records from record 1, and then from record 2.
Just change the limit in your model to:
$this->db->limit($per_page, $offset * $per_page);
I'm using codeigniter 3 and using hmvc for admin but problem pagination no showing First a Last link.i could not understand where is the problem
$config['per_page'] = 2;
$config['base_url'] = base_url().'admin/manage-cms';
$config['num_links'] = 20;
$config['uri_segment'] = 3;
$page = $this->uri->segment(3);
$limit_end = ($page * $config['per_page']) - $config['per_page'];
if ($limit_end < 0){
$limit_end = 0;
}
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$data['count_cms']= $this->cms_model->count_cms();
$config['total_rows'] = $data['count_cms'];
$data['cms'] = $this->cms_model->get_cms($config['per_page'],$limit_end);
$this->pagination->initialize($config);
i also updated the code to
$config['per_page'] = 2;
$config['base_url'] = base_url('admin/manage-cms');
$config['num_links'] = 20;
$config['uri_segment'] = 3;
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$data['count_cms']= $this->cms_model->count_cms();
$config['total_rows'] = $data['count_cms'];
$data['cms'] = $this->cms_model->get_cms($config['per_page'],$page);
$this->pagination->initialize($config);
But following problem have found
1)in url, pagination coming like url/2,url/4,url/6 etc
But i trying to show url/1,url/2,url/3
2) I have inserted 9 records in db but still First and Last link is not displayed
I have pagination in frontend index page example.com when I click page two of pagination I want to load page like eg example.com/1.
<?php
function index()
{
$e = $this->employer_model->count_jobs_with_employer();
//print_r($e) ;
$config['base_url'] = $this->config->site_url(); //set the base url for pagination
$config['total_rows'] = $e; //total rows
$config['per_page'] = '10'; //the number of per page for pagination
$config['uri_segment'] = 1; //see from base_url. 3 for this case
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$config['full_tag_open'] = '<div class="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config); //initialize pagination
$page = ($this->uri->segment(1)) ? $this->uri->segment(1) : 0;
$joblist['listemp'] = $this->employer_model->employerbyjob($config['per_page'], $page);
foreach($joblist['listemp'] as $emp)
{
$joblist['jobs'][$emp->u_id] = $this->employer_model->get_ByTbl_Col('employer_post_job', 'e_id', $emp->u_id,'dead_line', date('Y-m-d'));
}
$c['job_list'] = $this->load->view('front/blocks/employer/job_list', $joblist, TRUE);
}
?>
Something like this should work:
application/config/routes.php:
//default routes:
$route['default_controller'] = "yourcontroller";
$route['404_override'] = '';
// your custom route:
$route['(:num)'] = "yourcontroller/index/$1";
application/controllers/Yourcontroller.php
function index($page = null)
{
}