Welcome Guest, Not a member yet? Register   Sign In
Pagination repeated query_string_segment ?
#1

[eluser]bunal[/eluser]
Hi Coders,

When i use pagination library with

Code:
$config['base_url'] = uri_string();

The per_page is repeated instead of being replaced with the new per_page var by the library

Code:
http://domain/box/review/listall/&per_page=1
http://domain/box/review/listall/&per_page=1&per_page=2
http://domain/box/review/listall/&per_page=1&per_page=2&per_page=3

Why do you think this may happen?
#2

[eluser]WebsiteDuck[/eluser]
It seems you already have the answer to your question...because you're setting the base_url to uri_string.

Try something like this:
Code:
$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$config['base_url'] .= "://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

or just set the base_url manually
#3

[eluser]bunal[/eluser]
@WebsiteDuck: I know the cause of the problem but guessed am i missing smthing?

The original pagination class should be handling/fixing this since there is no logic in this.

I have fixed it by extending the class. Anyone having the same problem here is the fix

Code:
class MY_Pagination extends CI_Pagination{

    function MY_Pagination()
    {

        parent::CI_Pagination();
        $this->CI = & get_instance();

    }

    function initialize($params = array())
    {
        if (count($params) > 0)
        {
            foreach ($params as $key => $val)
            {
                if (isset($this->$key))
                {
                    $this->$key = $val;
                }
            }
        }
        $this->tidy_base_url();
    }

    function tidy_base_url(){
        if ($this->CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
        {
            if(strpos($this->base_url, '&') === false){
                $this->base_url .= "/";
            }
            
            $pattern = "#(&{$this->query_string_segment}=[\w]+)#is";
            $this->base_url = preg_replace($pattern, '', $this->base_url);

            
            $this->base_url  = str_replace('&', '&', $this->base_url);
        }
    }

}




Theme © iAndrew 2016 - Forum software by © MyBB