From 88cf55bd294e74c71e70406e3a48e722db224f7f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 17 Jan 2014 15:38:30 +0200 Subject: Add autoloading library aliasing support (supersedes PR #2824) --- application/config/autoload.php | 5 +++++ system/core/Loader.php | 11 +++++++++-- user_guide_src/source/changelog.rst | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/application/config/autoload.php b/application/config/autoload.php index 5a20c943a..43d53155b 100644 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -77,6 +77,11 @@ $autoload['packages'] = array(); | Prototype: | | $autoload['libraries'] = array('database', 'email', 'xmlrpc'); +| +| You can also supply an alternative library name to be assigned +| in the controller: +| +| $autoload['libraries'] = array('user_agent' => 'ua'); */ $autoload['libraries'] = array(); diff --git a/system/core/Loader.php b/system/core/Loader.php index 78172580d..8c8d5a37c 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -184,9 +184,16 @@ class CI_Loader { } elseif (is_array($library)) { - foreach ($library as $class) + foreach ($library as $key => $value) { - $this->library($class, $params); + if (is_int($key)) + { + $this->library($value, $params); + } + else + { + $this->library($key, $params, $value); + } } return $this; diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 8618e5efe..539c61367 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -408,7 +408,7 @@ Release Date: Not Released - Added autoloading of drivers with ``$autoload['drivers']``. - ``$config['rewrite_short_tags']`` now has no effect when using PHP 5.4 as ``