site_url()

site_url([$uri = ''[, $protocol = NULL]])

Parameters:
  • $uri (string) – URI string
  • $protocol (string) – Protocol, e.g. ‘http’ or ‘https’
Returns:

Site URL

Return type:

string

Returns your site URL, as specified in your config file. The index.php file (or whatever you have set as your site index_page in your config file) will be added to the URL, as will any URI segments you pass to the function, plus the url_suffix as set in your config file.

You are encouraged to use this function any time you need to generate a local URL so that your pages become more portable in the event your URL changes.

Segments can be optionally passed to the function as a string or an array. 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

Here is an example of segments passed as an array:

$segments = array('news', 'local', '123');
echo site_url($segments);

This function is an alias for CI_Config::site_url(). For more info, please see the Config Library documentation.

doc_CodeIgniter
2016-10-15 16:32:40
Comments
Leave a Comment

Please login to continue.