CodeIgniter Pagination URL with GET Parameters

codeigniter

In situations like searching for matching data from database (with pagination), we need to pass some data in the URL as GET parameter. But in CodeIgniter, many programmers face trouble while setting up pagination with parameters in the URL.

For example:

If you want to search for all authors from a list of users, your URL will be like this:
search/?type=authors

But it won’t not work directly with pagination.

So here is a quick fix for using GET parameters with pagination.

In pagination config use the following script:

if (count($_GET) > 0) $config['suffix'] = '?' . http_build_query($_GET, '', "&");
$config['first_url'] = $config['base_url'].'?'.http_build_query($_GET);

Your current $_GET variables will appear in pagination links also.

Have something to Add?

Loading Facebook Comments ...
Loading Disqus Comments ...