summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/helpers/url_helper.php28
-rw-r--r--user_guide_src/source/changelog.rst1
-rw-r--r--user_guide_src/source/helpers/url_helper.rst6
3 files changed, 26 insertions, 9 deletions
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;
}
}
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 6be6084c9..6f08dcb92 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -76,6 +76,7 @@ Release Date: Not Released
- Added support (auto-detection) for HTTP/1.1 response code 303 in :php:func:`redirect()`.
- Changed :php:func:`redirect()` to only choose the **refresh** method only on IIS servers, instead of all servers on Windows (when **auto** is used).
- Changed :php:func:`anchor()`, :php:func:`anchor_popup()`, and :php:func:`redirect()` to support protocol-relative URLs (e.g. *//ellislab.com/codeigniter*).
+ - Added an optional second parameter to both :php:func:`base_url()` and :php:func:`site_url()` that allows enforcing of a protocol different than the one in the *base_url* configuration setting.
- :doc:`HTML Helper <helpers/html_helper>` changes include:
diff --git a/user_guide_src/source/helpers/url_helper.rst b/user_guide_src/source/helpers/url_helper.rst
index 8b5361f94..7a49f188d 100644
--- a/user_guide_src/source/helpers/url_helper.rst
+++ b/user_guide_src/source/helpers/url_helper.rst
@@ -18,9 +18,10 @@ The following functions are available:
site_url()
==========
-.. php:function:: site_url($uri = '')
+.. php:function:: site_url($uri = '', $protocol = NULL)
:param string $uri: URI string
+ :param string $protocol: Protocol, e.g. 'http' or 'https'
:returns: string
Returns your site URL, as specified in your config file. The index.php
@@ -51,9 +52,10 @@ please see the :doc:`Config Library <../libraries/config>` documentation.
base_url()
===========
-.. php:function:: base_url($uri = '')
+.. php:function:: base_url($uri = '', $protocol = NULL)
:param string $uri: URI string
+ :param string $protocol: Protocol, e.g. 'http' or 'https'
:returns: string
Returns your site base URL, as specified in your config file. Example::