Codeigniter pagination issue with uri_segment - codeigniter

this is how my url looks,
http://example.com/Admin/uploadQuestionsForSections/1/2 (fourth segment is the page number for pagination. 3rd segment is the id). Problem is , clicking on pagination links dont serve up the correct records. All pages show the same records. I have provided below the pagination configuration:
$config["uri_segment"] = 4;
$config['base_url'] = base_url().'Admin/uploadQuestionsForSections/'.$this->uri->segment(3).'';
$config['use_page_numbers'] = TRUE;
$config['total_rows'] = $allcount;
$config['per_page'] = $rowperpage;
==
However it doesn't work. Help will be appreciated

Try this:
$config['base_url'] = base_url($this->uri->uri_string().'/');

Related

how to make codeigniter routing to work with paging

I have the following routes for the news that works like a charm:
$word5 = urlencode('mygreek-keyword-here');
$route[$word5] = "news/displayAllNews";
and this page display all news with the desired keyword in the address bar. But...there is always a but...I have paging on this page, so when i click on next page link...page works but with old non-friendly seo url, that is:
news/displayAllNews/10/10
while I would like to have is: mygreek-keyword-here/10/10
code that i have in my controller for the paging is as follow:
$config['base_url'] = site_url('/news/displayAllNews/'.$limit.'/');
what should i do in routes.php and in my controller to get the desired result?
Regards, John
You could get the string of URI by $this->uri->uri_string() method, and set the pagination config as follows:
$config['base_url'] = site_url($this->uri->uri_string() .'/'. $limit.'/');
Note that the URI library is loaded automatically, it doesn't need to load it manually.
Update:
Change the route rule to:
$route["$word5(.*)"] = "news/displayAllNews$1";
If it doesn't work yet, remove the .'/'. $limit.'/' phrase and let the pagination to add the limit itself by:
$config['per_page'] = 10; // or $limit, default items per page.
$config['use_page_numbers'] = FALSE;

CodeIgniter Pagination configuration is wrong?

Please take a look at the following code in a controller named "test":
$this->load->library('pagination');
// These 3 are the minimum config that needs to be set
$config['base_url'] = base_url() . 'test/?' . http_build_query($_GET, '', '&');
$config['total_rows'] = 173;
$config['per_page'] = 20;
// This returns something like this: ?name=foo/20
// I would expect something like this: ?name=foo&per_page=20
// $config['enable_query_strings'] = TRUE;
// This retuns something like this: ?name=foo&per_page=20 (which is what I want),
// but the documentation says it should be: ?c=test&m=index&per_page=20
$config['page_query_string'] = TRUE;
$this->pagination->initialize($config);
echo $this->pagination->create_links();
Then go to: test/?name=foo
The resulting pagination links look correct. When you click on, say, link number "2", you are redirected to ?name=foo&per_page=20 which is correct. However, the new pagination created looks wrong. It looks something like this: ?name=foo&per_page=20&per_page=40 (where per_page appears twice in the query string).
What's going on?
add uri segments
$config['uri_segment'] = x ;

CodeIgniter: howto override Pagination configuration in controller code?

I recently jumped on the CodeIgniter train because I finally want to embrace the MVC architecture for my growing PHP/MySQL projects.
Right now I encounter a probolemin the PAgination configuratino that is apparently not described earlier as far as I can ssee.
Probably the issue is not PAgination only related but more general. In my first attempt, I just filled the confiuration in the controller method and passed it to the initialize() method:
$config['base_url'] = $this->config->base_url() . "/categorie/{$catName}/";
$config['total_rows'] = $this->event_model->get_nrofevents_for_categorie($categorieObject->id, TRUE);
$config['per_page'] = 12;
$config['full_tag_open'] = '<div class="paging">';
$config['full_Tag_close'] = '</div>';
$config['prev_link'] = 'Vorige';
$config['next_link'] = 'Volgende';
$this->pagination->initialize($config);
And this works fine. But I have a buch of other pages that use the same pagination with most of its parameteres identical, only the base_url and the total_rows config properties are different for each page.
I have put the common configuration in the config/pagination.php configuration file but see no option to add the page-dependent properties in the code.
More general, is it possible to put generic configuration in a config file and add some customized properties in the controller method?
For me this seems logical but cannot figure out how...
I tried something like:
$this->load->config('pagination');
$this->config->set_item('next_link', 'blablabla');
but it seems that the Pagination is initialized immediately after reading the config file and this code has no effect.
Please any suggestions?
Since the initialize() only replaces the keys you provide, you can have your config/pagination.php hold the default values and call initialize() with the changing ones.
config/pagination.php
// put default values here
$config['next_link'] = 'Volgende';
$config['prev_link'] = 'Vorige';
// ...
controller
$this->pagination->initialize(array(
'base_url' => base_url().'categorie/'.$catName.'/',
'total_rows' => $totalRows,
// ...
)));
don't use base_url()... I always use site_url();
$config['base_url'] = site_url('');

pagination first link disabled codeigniter

I am using codeigniter pagination. The first link is disabled and the rest of the links are working. Even after going to the 2nd and 3rd link the first link remains disabled.
Controller
$this->load->library('pagination');
$config['base_url'] = base_url().'/le0wallt1esadmin/specialoffer/viewsp/';
$config['total_rows'] = $this->db->count_all('home');
$config['per_page'] =5;
$config['use_page_numbers'] = TRUE;
$config['uri_segment'] = 4;
$this->pagination->initialize($config);
Thanks,
it is the current pagination behaviour of the codeigniter pagination library. to override this, you can specify
$config["cur_tag_open"] = "<a href='" + current_url() + "'>";
$config["cur_tag_close"] = "</a>";
and then you'll have the current page link.

Codeigniter's Pagination is not working

I am trying to display information from mysql database based on user's query . I have a form and after a user submits data, it goes to the controller I have posted below and then to a view file where it shows the information the user wanted.
So far I am good with this, but the problem creates with the pagination. At present I have eight rows of data to display from my database, so to check if the pagination is working well I set the $config['per_page'] value to 5 (please check below). And now when I click on the next button, it doesn't show any data.
I think the problem lies in the fact that when I click on the "next" button, it goes to the controller again but this time the controller is not getting the values the user posted in the first place.
Would you please kindly help me with this?
Thank in Advance :)
My Controller:
function show(){
$batchid=$this->input->post('batchid');
$daterange1=$this->input->post('daterange1');
$daterange2=$this->input->post('daterange2');
$this->load->library('pagination');
$config['base_url'] = base_url().'markslist/show';
$this->db->select('*');
$this->db->from('marks');
$this->db->where('examdate', $daterange1);
$this->db->where('examdate', $daterange2);
$this->db->join('student', 'marks.studentid = student.studentid');
$this->db->where('batchid', $batchid);
$this->db->order_by('batchid','DESC');
$query = $this->db->get('');
$numrows=$query->num_rows();
$config['total_rows'] = $numrows;
$config['per_page'] = 5;
$config['num_links'] = 20;
$config['full_tag_open'] = '<div class="pagination" align="center">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
// To get the subject lists
$this->load->model('mod_markslist');
$data['records']= $this->mod_markslist->listmarks($batchid,$daterange1,$daterange2,$config['per_page'],$this->uri->segment(3));
$data['main_content']='view_markslist';
$this->load->view('includes/template',$data);
}
I would copy the initial posted data to session:
if($this->input->post()){
$this->session->set_userdata('batchid', $this->input->post('batchid'));
$batchid = $this->input->post('batchid');
/* similar for the other posted fields */
}
else{
$batchid = $this->session->userdata('batchid');
/* similar for other fields now in session */
}
/* load pagination library etc */
Best to also do a check if the information is available in session as well though.

Resources