From 2023c3d05b042cf1322286d69557c2b8bf3bd8d5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 18 Jul 2013 03:19:59 +0300 Subject: Add an optional parameter to URL helpers base_url() and site_url() (supersedes #2535) --- system/helpers/url_helper.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'system/helpers/url_helper.php') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index d0fab3fe0..36219630d 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -46,13 +46,20 @@ if ( ! function_exists('site_url')) * Create a local URL based on your basepath. Segments can be passed via the * first parameter either as a string or an array. * - * @param string + * @param string $uri + * @param string $protocol * @return string */ function site_url($uri = '') { - $CI =& get_instance(); - return $CI->config->site_url($uri); + $site_url = get_instance()->config->site_url($uri); + + if (isset($protocol)) + { + $site_url = $protocol.substr($site_url, strpos($site_url, '://')); + } + + return $site_url; } } @@ -67,13 +74,20 @@ if ( ! function_exists('base_url')) * 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. * - * @param string + * @param string $uri + * @param string $protocol * @return string */ - function base_url($uri = '') + function base_url($uri = '', $protocol = NULL) { - $CI =& get_instance(); - return $CI->config->base_url($uri); + $base_url = get_instance()->config->base_url($uri); + + if (isset($protocol)) + { + $base_url = $protocol.substr($base_url, strpos($base_url, '://')); + } + + return $base_url; } } -- cgit v1.2.3-24-g4f1b