diff options
author | Andrey Andreev <narf@devilix.net> | 2016-01-04 11:34:14 +0100 |
---|---|---|
committer | Andrey Andreev <narf@devilix.net> | 2016-01-04 11:34:14 +0100 |
commit | 0b1efb38293416b13aee8d1d9505e97d2efade5f (patch) | |
tree | aff933520f6735cef86376348da26a51bab6fddb | |
parent | 6bb9170b2f19b5b327e5c6998cbce414c5d28b50 (diff) |
Fix #4350
-rw-r--r-- | system/core/Loader.php | 32 | ||||
-rw-r--r-- | user_guide_src/source/changelog.rst | 1 |
2 files changed, 32 insertions, 1 deletions
diff --git a/system/core/Loader.php b/system/core/Loader.php index 18e4c5287..87f21b279 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -285,9 +285,39 @@ class CI_Loader { $this->database($db_conn, FALSE, TRUE); } + // Note: All of the code under this condition used to be just: + // + // load_class('Model', 'core'); + // + // However, load_class() instantiates classes + // to cache them for later use and that prevents + // MY_Model from being an abstract class and is + // sub-optimal otherwise anyway. if ( ! class_exists('CI_Model', FALSE)) { - load_class('Model', 'core'); + $app_path = APPPATH.'core'.DIRECTORY_SEPARATOR; + if (file_exists($app_path.'Model.php')) + { + require_once($app_path.'Model.php'); + if ( ! class_exists('CI_Model', FALSE)) + { + throw new RuntimeException($app_path."Model.php exists, but doesn't declare class CI_Model"); + } + } + elseif ( ! class_exists('CI_Model', FALSE)) + { + require_once(BASEPATH.'core'.DIRECTORY_SEPARATOR.'Model.php'); + } + + $class = config_item('subclass_prefix').'Model'; + if (file_exists($app_path.$class.'.php')) + { + require_once($app_path.$class.'.php'); + if ( ! class_exists($class, FALSE)) + { + throw new RuntimeException($app_path.$class.".php exists, but doesn't declare class ".$class); + } + } } $model = ucfirst($model); diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 09b51ce68..c189767d8 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -30,6 +30,7 @@ Bug fixes for 3.0.4 - Fixed a bug where :doc:`Database <database/index>` method `version()` returned banner text instead of only the version number with the 'oci8' and 'pdo/oci' drivers. - Fixed a bug (#4331) - :doc:`Database <database/index>` method ``error()`` didn't really work for connection errors with the 'mysqli' driver. - Fixed a bug (#4343) - :doc:`Email Library <libraries/email>` failing with a *"More than one 'from' person"* message when using *sendmail*. +- Fixed a bug (#4350) - :doc:`Loader Library <libraries/loader>` method ``model()`` logic directly instantiated the ``CI_Model`` or ``MY_Model`` classes. Version 3.0.3 ============= |