Welcome Guest, Not a member yet? Register   Sign In
pagination with parameters! (filtering)

I tested standard pagination library  and it's work like a charm.

But i wanna users to have ability to use filters - for instance - price - from - to, region, category. There could be a lot of them. So how can i implement this?

I think just pass parameters by get, but it this case pagination buttons would be without get, and user's choice would be lost after he/she clicked on the page...

Does somebody encounter this?

How permanent are the filter choices? Just for that one page and reset on next visit, permanent choice for navigating away and back, for this page and others, for the next session?

For instance, suppose you had filters 'By Newest', 'By Biggest' and 'By Best'. Your controller could look for a variable in the url, then load it into subsequent page links like below in the pagination class:

PHP Code:
$config['base_url'] = 'http://example.com/index.php/test/page/biggest' 

Or your controller could read a session variable, and sort the results on the filter defined in that. Then you would not need to load the url but test for the existence of the session variable, and set it to the default if not found. Your database query would then use the session value for the filter to constrain your results. The filter option link would link to a function that set the chosen filter into the session.

Alternatively you could see this as a user setting, and store the filter option as a user setting in your database. Or you could set it in a separate cookie. There are lots of ways of doing this. What suits you is up to you.

Hope that helps,


Yeah i thought about ways you just described, but i want to really short lived filter choices. -
only within the search controller, so if user clicks on any another link it's gone.

I thought there can be some sot of [sufix] variable within pagination system.
For me the best way just add suffix to each url that pagination system generates.
so i get mysite/search/page/1?param1=&param=2&param4 and so on.

(This post was last modified: 07-24-2017, 11:51 AM by glorsh66.)

i have found this solution -
but have not tried yet. So if somebody encounter such problem you can use that

(07-24-2017, 11:51 AM)glorsh66 Wrote: i have found this solution -
but have not tried yet. So if somebody encounter such problem you can use that

Just for warning new users
The question on stackoverflow linked above is really ancient and has nothing to do with current CodeIgniter 4 methods

(This post was last modified: 08-30-2021, 12:43 PM by IvanBell.)

I have a website that combines pagination and filtering. You can use GET method, receive the data in controller, unset "page" key and proceed to the model with the rest. Please see my old question, perhaps it will be of help for you:
Query Builder "Where" with Array

Another way is to add an extra key to all inputs in your form. So you can have inputs like
<input name="filter[price] value="" />

<input name="filter[category] value="" />
and so on. Then in controller you can pass to the model
This way page will not be included

@includebeer has some nice tutorials for recipes that the pagination is using seqarch in them.


IncludeBeer - Blog - Recipes CodeIgniter 4 Tutorials
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

Theme © iAndrew 2016 - Forum software by © MyBB