Welcome Guest, Not a member yet? Register   Sign In
Nasty little bug - easy fix
#5

I have updated the site_url method of MY_url_helper

PHP Code:
    /**
     * Site URL updated to set a correct URL when passing only white space
     * or passing an query string starting with a "?"
     *
     * Returns base_url . index_page [. uri_string]
     *
     * @uses CI_Config::site_url()
     *
     * @param string|string[] $uri URI string or an array of segments
     * @param string $protocol
     * @return string
     */
 
   function site_url($uri ''$protocol NULL) {
 
       // Get the CI super object
 
       $ci =& get_instance();
 
 
       // Get the set suffix
 
       $suffix $ci->config->config['url_suffix'];
 
 
       // Check if uri is an array
 
       ifis_array($uri) ) {
 
           $uri implode('/'$uri);
 
       }

 
       // Trim all white space
 
       $uri trim($uri);
 
 
       // Is a "?" present and the first character?
 
       if( ($offset strpos($uri'?')) !== FALSE && $offset === 0) {
 
           // Lets clear the config item for this call
 
           $ci->config->set_item('url_suffix''');
 
 
           // Get the site url from the original site_url method
 
           $site_url $ci->config->site_url($uri$protocol);
 
 
           // Reset the suffix
 
           $ci->config->set_item('url_suffix'$suffix);
 
 
           // Lets remove the "/" in front of the ?
 
           $base_url $ci->config->config['base_url'];
 
           $new_uri str_replace(base_url(), ''$site_url);
 
           ifstrlen($new_uri) > 0) {
 
               $site_url $base_url.$new_uri;
 
               return $site_url;
 
           }
 
           // We should never reach this line
 
           return $site_url;
 
       }
 
 
       return $ci->config->site_url($uri$protocol);

Reply


Messages In This Thread
Nasty little bug - easy fix - by Nicolaus.Sommer - 11-07-2015, 05:49 AM
RE: Nasty little bug - easy fix - by Martin7483 - 11-07-2015, 08:41 AM
RE: Nasty little bug - easy fix - by Martin7483 - 11-07-2015, 10:41 AM
RE: Nasty little bug - easy fix - by Martin7483 - 11-07-2015, 11:49 AM



Theme © iAndrew 2016 - Forum software by © MyBB