diff options
author | Andrey Andreev <narf@devilix.net> | 2013-10-26 13:15:02 +0200 |
---|---|---|
committer | Andrey Andreev <narf@devilix.net> | 2013-10-26 13:15:02 +0200 |
commit | 28a3692b2b43d9ffd0eb7668fb64c3347c676722 (patch) | |
tree | 5a25efde552a13d2df616fa8fe573125c68e57c6 /system/core | |
parent | a587a939ce0b8e7d1dfe0830ac83d881e151d6e0 (diff) | |
parent | 8c0e56f5349cb52e993eb7132a87151e838e95b0 (diff) |
Merge pull request #2699 from vlakoff/url-functions
Implement $protocol parameter in Config base_url() and site_url() methods
Diffstat (limited to 'system/core')
-rw-r--r-- | system/core/Config.php | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/system/core/Config.php b/system/core/Config.php index 109ee6424..a0e830abe 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -228,13 +228,21 @@ class CI_Config { * @uses CI_Config::_uri_string() * * @param string|string[] $uri URI string or an array of segments + * @param string $protocol * @return string */ - public function site_url($uri = '') + public function site_url($uri = '', $protocol = NULL) { + $base_url = $this->slash_item('base_url'); + + if (isset($protocol)) + { + $base_url = $protocol.substr($base_url, strpos($base_url, '://')); + } + if (empty($uri)) { - return $this->slash_item('base_url').$this->item('index_page'); + return $base_url.$this->item('index_page'); } $uri = $this->_uri_string($uri); @@ -255,14 +263,14 @@ class CI_Config { } } - return $this->slash_item('base_url').$this->slash_item('index_page').$uri; + return $base_url.$this->slash_item('index_page').$uri; } elseif (strpos($uri, '?') === FALSE) { $uri = '?'.$uri; } - return $this->slash_item('base_url').$this->item('index_page').$uri; + return $base_url.$this->item('index_page').$uri; } // ------------------------------------------------------------- @@ -275,11 +283,19 @@ class CI_Config { * @uses CI_Config::_uri_string() * * @param string|string[] $uri URI string or an array of segments + * @param string $protocol * @return string */ - public function base_url($uri = '') + public function base_url($uri = '', $protocol = NULL) { - return $this->slash_item('base_url').ltrim($this->_uri_string($uri), '/'); + $base_url = $this->slash_item('base_url'); + + if (isset($protocol)) + { + $base_url = $protocol.substr($base_url, strpos($base_url, '://')); + } + + return $base_url.ltrim($this->_uri_string($uri), '/'); } // ------------------------------------------------------------- |