I am having trouble setting up pagination on codeigniter when I pass parameters in the URL
if my url is like this : search/?type=groups
what sho
Had the same problem but realized that newer versions of CI have a suffix defined within the pagination class. Though it's still not in the documentation. No need to hack it.
I got the same problem. My solution is to modify Pagination and put it in application/libraries. First i create
var $get='';
and find all "a" elements and add $get in the href="........'.$this->get.'"'>.......</a>
Now in the controller or model input these line
$config['get']=(isset($_GET['search']))?'?search='.$_GET['search']:'';
That's it! i hope it will help you.
Before line:
$this->base_url = rtrim($this->base_url).'&'.$this->query_string_segment.'=';
Replace this code below:
if(isset($_GET[$this->query_string_segment]))
{
unset($_GET[$this->query_string_segment]);
}
$uri = http_build_query($_GET);
$uri = empty($uri) ? '?' : $uri . '&';
$this->base_url = rtrim($this->base_url).$uri.$this->query_string_segment.'=';
I struggled with the same issue today. My solution is this:
Generate the pagination links and store them in a string ( $pagination = $this->pagination->create_links();
)
Use regexp to find all links and add query strings
The regular expression code used is:
<?php
$query = '?myvar=myvalue';
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
$unique = array();
if( preg_match_all("/$regexp/siU", $pagination, $matches) )
{
foreach ( $matches[2] as $link )
{
if ( !isset($unique[$link]) )
{
$data['pagination'] = str_replace($link . '"', $link . $query . '"', $data['pagination']);
$unique[$link] = '';
}
}
}
unset($unique);
Works like a charm for me! What it does is:
Then just assign the variable to the template that will be shown and use print $your_pagination_variable_name; to show the links with your query-strings attached!
I have encountered with similar kind of problem, and based on the above answer here is what I have to do for customization according to my needs.
My URI was to be something like this:
base_url() . /search/?term=
So, here is what I have done:
$config['base_url'] = base_url ."/search/?term=" . $_GET['term']
Just see this link.
Just update the modified pagination class and then add
$config['get'] = "?string=" . $_REQUEST['string']."&searchBy=" . $_REQUEST['searchBy'];