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
I want to create a URL containing string from search form and page from pagination
For example, my base URL is example.com/search
When showing the search result it will be example.com/search/?s=keyword and when showing the search result from next page it will be example.com/search/?s=term&p=2 for second page and so on
How to make it like that in CodeIgniter?
try this. here used page instead of p in URL
$keyword = trim($this->input->get('s', TRUE));
$this->load->library('pagination');
$config['total_rows'] = $this->db->get('table_name')->num_rows();
$config['per_page'] = 10;
$config['num_links'] = 5;
$config['enable_query_strings'] = TRUE;
$config['use_page_numbers'] = TRUE;
$config['query_string_segment'] = 'page';
$config['page_query_string'] = TRUE;
$config['base_url'] = site_url('search/index/?s=' . $keyword);
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
if ($this->input->get('page')) {
$sgm = (int) trim($this->input->get('page'));
$segment = $config['per_page'] * ($sgm - 1);
} else {
$segment = 0;
}
$this->pagination->initialize($config);
// your query
$query = $this->db->select('*')->from('table_name')->limit($config['per_page'], $segment)->get();
now your URL will be same as you mention in your question
$this->load->library('pagination');
$config['base_url'] = base_URL().'admin/issues/list_issues/';
$config['total_rows'] = $this->db->get('dt_issues')->num_rows();
$config['num_links']=10;
$config['per_page'] = 5;
$config['uri_segment'] = 3;
Codeigniter pagination was working properly. But when click on first link it is not working and the remaining links will work. Please help me.
$offset is the variable in which u can get value which page user is reqesting
function list_issues($offset = null)
{
$this->load->library('pagination');
........
// Pagination config
$config['base_url'] = base_URL().'admin/issues/list_issues/';
$config['total_rows'] = $this->provider_model->countprovider();
$config['per_page'] = 3;
// $config['creat_link'] = 1; <-- This is not a valid option
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
// Init config
$this->pagination->initialize($config);
// If the pagination library doesn't recognize the current page add:
$this->pagination->cur_page = $offset;
.....
// further your code
}
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)
{
}
I have set rout as
$route['dog/(:any)'] = "dog/index/$1"; /// for single dog info
$route['dog/list'] = "dog/listing"; /// for dog list, display all dogs.
$route['dog/list/(:num)'] = "dog/listing/$1"; /// for pagination
single dog url is like dog/dogName-4.html
my controller is as
public function index()
{
$dogInfo = $this->uri->segment(2);
if ($dogInfo != "")
{
$dogDetails = explode('-', $dogInfo);
$this->load->view('common/header',$header);
$this->load->view('dog/dog_info', $content);
$this->load->view('common/footer', $footer);
}
else
redirect('welcome', 'location', 301);
}
public function listing()
{
$this->load->library("pagination");
$breed = $this->input->get('breed');
$gender = $this->input->get('gender');
$state = $this->input->get('state');
$seller = $this->input->get('seller');
$config = array();
$config["base_url"] = base_url() . "dog/list/";
$config["total_rows"] = $this->dogs->get_dog_list_count($breed, $gender, $state, $seller);
$config["per_page"] = 5;
$config["uri_segment"] = 2;
$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);
$page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
$content['details'] = $this->dogs->get_dog_list($config["per_page"], $page,$breed, $gender, $state, $seller);
$content['paginatonLinks'] = $this->pagination->create_links();
$content['total_dogs'] = $config['total_rows'];
$content['cur_page'] = $page + 1;
$content['total_pages'] = ceil($config["total_rows"] / $config["per_page"]);
$this->load->view('common/header');
$this->load->view('dog/dog_list', $content);
$this->load->view('common/footer', $footer);
}
The controller's index function is to display information about one dog, and listing function is for all the dogs,
I have to set pagination for listing function i did set all the required variables for pagination, pagination displaying the result as well
Found [134] Ads :: Page 1 of 27 1 2 3 > Last ›
but when i click on the pagination 1 2 3 else on page it brings me to the index page.
I need to be on the listing function of the controller. please any one help me.
here is the updated code
the rout code is
$route['dog/list'] = "dog/listing";
$route['dog/list/(:num)'] = "dog/listing/$1";
$route['dog/(:any)'] = "dog/index/$1";
and here is the updated controller code
$config = array();
$config["base_url"] = base_url() . "dog/list/";
$config['suffix'] = '?'.http_build_query($_GET, '', "&");
$config["total_rows"] = $this->dogs->get_dog_list_count($breed, $gender, $state, $seller);
$config["uri_segment"] = 3;
$config["per_page"] = 5;
$config['use_page_numbers'] = TRUE;
$config['full_tag_open'] = '<div class="pagination">';
$config['full_tag_close'] = '</div>';
$config['cur_tag_open'] = '<a href="#" class="page_selected">';
$config['cur_tag_close'] = '</a>';
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$this->load->model('DogsListing_model', 'dogs');
$this->load->model('Breed_model', 'breeds');
$content['breeds'] = $this->breeds->get_all_id_title();
$content['details'] = $this->dogs->get_dog_list($config["per_page"], $page,$breed, $gender, $state, $seller);
$content['search'] = array('breed' => $breed, 'gender' => $gender, 'state' => $state, 'seller' => $seller);
$content['paginatonLinks'] = $this->pagination->create_links();
$content['total_dogs'] = $config['total_rows'];
$content['cur_page'] = $page + 1;
$content['total_pages'] = ceil($config["total_rows"] / $config["per_page"]);
i have found the solution of my question
first i have use $this->uri->segment(3) and $config["uri_segment"] = 3; i was using a wrong uri->segment for pagination. this solve my problem related to pagination.
my next part is i have to set variables for seller or search results with the pagination. for example i have the url doglist.html/?seller=29 i need to embed pagination with this pagination. so that the result will be like dog/list/3?breed=&gender=female&state=&submit2=Fetch i have solve this issue with this line of code $config['suffix'] = '?'.http_build_query($_GET, '', "&"); now my pagination with variables works fine.
Thanks to #jtheman and #Venkat, but mostly #jtheman for their contributings.
If you have any doubt related to pagination check out this generalised function which i wrote as answer to another question.