CodeIgniter Forums
base_url() function and documentation not consistent? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: base_url() function and documentation not consistent? (/showthread.php?tid=46352)



base_url() function and documentation not consistent? - El Forum - 10-28-2011

[eluser]Unknown[/eluser]
Code:
/**
* Base URL
*
* Returns the "base_url" item from your config file
*
* @access public
* @return string
*/
if ( ! function_exists('base_url'))
{
function base_url()
{
  $CI =& get_instance();
  return $CI->config->slash_item('base_url');
}
}

That's the function I got from 2.0.3 core. There aren't any input parameters.

The documentation, (codeigniter dot com/user_guide/helpers/url_helper.html) says,

Quote:base_url()

Returns your site base URL, as specified in your config file. Example:
Code:
echo base_url();
This function returns the same thing as site_url, without the index_page or url_suffix being appended.

Also like site_url, you can supply segments as a string or an array. Here is a string example:

Code:
echo base_url("blog/post/123");
The above example would return something like: http://example.com/blog/post/123

This is useful because unlike site_url(), you can supply a string to a file, such as an image or stylesheet. For example:
Code:
echo base_url("images/icons/edit.png");
This would give you something like: http://example.com/images/icons/edit.png

My reason for wanting to use this function was because site_url wasn't smart enough to realize that when I fed it the link to an image, it shouldn't append the .html suffix that I have stuck in the url_suffix section of the config.

Thanks,


Thom Brooks
Austin, TX