codeigniter pagination url with get parameters

后端 未结 15 1807
野的像风
野的像风 2020-12-12 14:52

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

相关标签:
15条回答
  • 2020-12-12 15:01

    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.

    0 讨论(0)
  • 2020-12-12 15:02

    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.

    0 讨论(0)
  • 2020-12-12 15:05

    Before line:

    $this->base_url = rtrim($this->base_url).'&amp;'.$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 . '&amp;';
    $this->base_url = rtrim($this->base_url).$uri.$this->query_string_segment.'=';
    
    0 讨论(0)
  • 2020-12-12 15:06

    I struggled with the same issue today. My solution is this:

    1. Generate the pagination links and store them in a string ( $pagination = $this->pagination->create_links(); )

    2. 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:

    1. Find all links
    2. Replace unique links (since there is a previous/next links same link may appear more than once) with the original link and the query-string.

    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!

    0 讨论(0)
  • 2020-12-12 15:14

    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']
    
    0 讨论(0)
  • 2020-12-12 15:16

    Just see this link.
    Just update the modified pagination class and then add

    $config['get'] = "?string=" . $_REQUEST['string']."&searchBy=" . $_REQUEST['searchBy']; 
    
    0 讨论(0)
提交回复
热议问题