Welcome Guest, Not a member yet? Register   Sign In
site_url() attaching suffix more than once with pagination
#1

[eluser]mrmeyers99[/eluser]
In my config file I have: $config['url_suffix'] = ".php";
When I initalize my pagination class I set

$config['base_url'] = site_url('controller/function/'.$param1);

For some reason when I do create_links() It prints out

http://localhost/controller/function/par...tion_start

for all the links. Then when I click on the link the next time it has 3 .phps.

To fix it I created a MY_Config class and changed the site_url() to the following:
Code:
if (is_array($uri))
        {
            $uri = implode('/', $uri);
        }

        if ($uri == '')
        {
            return $this->slash_item('base_url').$this->item('index_page');
        }
        else
        {
            $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
            $url = $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri);

            return strripos($url, $suffix) === FALSE ? $url.$suffix :$url;
        }

That fixed this error. This was only a problem with the pagination class, but I would recommend adding the check to see if the suffix is already there.




Theme © iAndrew 2016 - Forum software by © MyBB