codeigniter pagination url with get parameters

后端 未结 15 1903
野的像风
野的像风 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: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:

    ]*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!

提交回复
热议问题