URL Helper

The URL Helper file contains functions that assist in working with URLs.

Loading this Helper

This helper is loaded using the following code:

$this->helper('url');

Available Functions

The following functions are available:

site_url($uri = '')
Parameters:
  • $uri (string) – URI string
Returns:

Site URL

Return type:

string

Returns your site URL, as specified in your config file.

Here is a string example:

echo site_url('news/local/123');

The above example would return something like: http://example.com/index.php/news/local/123

base_url()
Returns:

Base URL

Return type:

string

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

echo base_url();
media_url($uri = '')
Parameters:
  • $uri (string) – URI string
Returns:

Site URL

Return type:

string

Returns your site URL included web folder.

Here is a string example:

echo media_url('image/logo.png');

The above example would return something like: http://example.com/web/image/logo.png

current_url()
Returns: The current URL
Return type: string

Returns the full URL (including segments) of the page being currently viewed.

uri_parameter($index = 1)
Parameters:
  • $index (int) – URI index
Returns: An URI string
Return type: string

Returns the URI segments of any page that contains this function. For example, if your URL was this:

http://some-site.com/blog/comments/123

The function would return:

echo uri_parameter(1); //return blog
redirect($uri = '', $method = 'auto')
Parameters:
  • $uri (string) – URI string
  • $method (string) – Redirect method (‘auto’, ‘location’ or ‘refresh’)
Return type:

void