Commits

Anonymous committed 878a7f6

Made config->base_url() accept parameters. config->base_url($uri). Updated base_url() in url_helper accordingly.

Comments (0)

Files changed (2)

system/core/Config.php

 	// --------------------------------------------------------------------
 
 	/**
-	 * Fetch a config file item - adds slash after item
-	 *
-	 * The second parameter allows a slash to be added to the end of
-	 * the item, in the case of a path.
+	 * Fetch a config file item - adds slash after item (if item is not empty)
 	 *
 	 * @access	public
 	 * @param	string	the config item name
 		{
 			return FALSE;
 		}
+		if( trim($this->config[$item]) == '')
+		{
+			return '';
+		}
 
 		return rtrim($this->config[$item], '/').'/';
 	}
 
 	/**
 	 * Site URL
+	 * Returns base_url . index_page [. uri_string]
 	 *
 	 * @access	public
 	 * @param	string	the URI string
 
 		if ($this->item('enable_query_strings') == FALSE)
 		{
+			$suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
+			return $this->slash_item('base_url').$this->slash_item('index_page').$this->_uri_string($uri).$suffix;
+		}
+		else
+		{
+			return $this->slash_item('base_url').$this->item('index_page').'?'.$this->_uri_string($uri);
+		}
+	}
+	
+	// -------------------------------------------------------------
+	
+	/**
+	 * Base URL
+	 * Returns base_url [. uri_string]
+	 * 
+	 * @access public
+	 * @param string $uri
+	 * @return string
+	 */
+	function base_url($uri = '')
+	{
+		return $this->slash_item('base_url').ltrim($this->_uri_string($uri),'/');
+	}
+	
+	// -------------------------------------------------------------
+	
+	/**
+	 * Build URI string for use in Config::site_url() and Config::base_url()
+	 * 
+	 * @access protected
+	 * @param  $uri
+	 * @return string
+	 */
+	protected function _uri_string($uri)
+	{
+		if ($this->item('enable_query_strings') == FALSE)
+		{
 			if (is_array($uri))
 			{
 				$uri = implode('/', $uri);
 			}
-
-			$index = $this->item('index_page') == '' ? '' : $this->slash_item('index_page');
-			$suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
-			return $this->slash_item('base_url').$index.trim($uri, '/').$suffix;
+			$uri = trim($uri, '/');
 		}
 		else
 		{
 					$str .= $prefix.$key.'='.$val;
 					$i++;
 				}
-
 				$uri = $str;
 			}
-
-			return $this->slash_item('base_url').$this->item('index_page').'?'.$uri;
 		}
+	    return $uri;
 	}
 
 	// --------------------------------------------------------------------
-
+	
 	/**
 	 * System URL
 	 *

system/helpers/url_helper.php

 
 /**
  * Base URL
- *
- * Returns the "base_url" item from your config file
+ * 
+ * Create a local URL based on your basepath.
+ * Segments can be passed in as a string or an array, same as site_url
+ * or a URL to a file can be passed in, e.g. to an image file.
  *
  * @access	public
+ * @param string
  * @return	string
  */
 if ( ! function_exists('base_url'))
 {
-	function base_url()
+	function base_url($uri = '')
 	{
 		$CI =& get_instance();
-		return $CI->config->slash_item('base_url');
+		return $CI->config->base_url($uri);
 	}
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.