On this article I’ll try to explain how to use CodeIgniter’s pagination library with a search term in a way that that our links look like:
Controller\action\search_term\page
CodeIgniter’s pagination library makes it easy for us to show long data lists generating tha links for the corresponding pages automatically, But it lacks a way to include a search term on the paginated results.
The problem is that if we inlcude a search term with the pagination, there is no specific function to include this search teram on the links for the following pages. As an extra complication we will solve this problem including a subset of data, on which we will apply both the pagination and an optional search term. And getting the links like this:
Controller\accion\id\termino de búsqueda\pagina.
We have the following scenario:
- A list of cities.
- A list of people who belong to a city.
- We want to list the people belonging to a determined city, and we want to paginate the results, but also we want to be able to search in this result set and have a paginated result, using the same view.