Losing URI segments when paginating with CodeIgniter Losing URI segments when paginating with CodeIgniter codeigniter codeigniter

Losing URI segments when paginating with CodeIgniter


Just for users coming from Google, here is the solution:

In the pagination config array, I changed my base_url for this:

$config['base_url'] = site_url('payments/index/' . $this->uri->segment(3) . '/' . $this->uri->segment(4));

Where segment(3) is my offset number and segment(4) is the hash. So, in this case, the hash may or may not exists and the pagination will still work.

Another approach could be this: If you go to payments, and there is no flashdata ID in the URL, it redirects the user to payments/search and create an empty array with empty filters. Then it redirects back to payments/_NEW_FLASHDATA_ID_HERE_. This way, the URL will always have a flashdata ID in the URL and you can have the pagination offset in the last URI segment as usual.


Why not set the hash as a session item?

$this->session->set_userdata('session_flashdata_hash', $hash);

The hash will then be available until you unset it

$this->session->unset_userdata('session_flashdata_hash');

Or until you destroy the session.

$this->session->sess_destroy();


Why aren't you checking to see if the hash exists and set the uri_segment based on that?