EllisLab text mark
Advanced Search
     
base_url() function and documentation not consistent?
Posted: 28 October 2011 12:53 PM
Joined: 2011-10-23
4 posts
/**
 * 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,

base_url()

Returns your site base URL, as specified in your config file. Example:

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:

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:

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

 
Posted: 28 October 2011 03:36 PM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2008-12-23
189 posts

are you sure you have the latest version? I just downloaded the 2.0.3 zip file and base_url() is defined like this

function base_url($uri '')
{
 $CI 
=& get_instance();
 return 
$CI->config->base_url($uri);
 
Posted: 28 October 2011 07:49 PM   [ # 2 ]   [ Rating: 0 ]
Joined: 2011-10-23
4 posts

Weird, thanks for the clarification.

I think I got my copy of 2.0.3 via the link from the post about reactor going public on:

codeigniter dot com/forums/viewthread/177924/ 

...from which, I navigated to…

bitbucket dot org/ellislab/codeigniter-reactor/downloads

...and grabbed tip.

The base_url function I quoted from was lines 61-64 of system/helpers/url_helper.php.

 
Posted: 29 October 2011 12:28 AM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2008-12-23
189 posts

ah right on. Yeah that is weird. Bitbucket has been abandoned in favor of Github (http://github.com/EllisLab/CodeIgniter) and it looks like the Bitbucket repo just hasn’t been updated since July. The best place to get the latest stable code is from the downloads page at http://codeigniter.com/downloads