summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authoradmin <devnull@localhost>2006-10-24 02:14:28 +0200
committeradmin <devnull@localhost>2006-10-24 02:14:28 +0200
commitc75b09fd0d96a3871a8b02cbf0182d09b80d96e4 (patch)
tree8a64aee10bc3469e01c9894a9af00924342446fe /system
parent41f908d57db3e5599b7f94f608f53e651dba43a6 (diff)
Diffstat (limited to 'system')
-rw-r--r--system/libraries/Model.php37
1 files changed, 31 insertions, 6 deletions
diff --git a/system/libraries/Model.php b/system/libraries/Model.php
index 240db4397..dfb48a5d0 100644
--- a/system/libraries/Model.php
+++ b/system/libraries/Model.php
@@ -26,6 +26,8 @@
*/
class Model {
+ var $_parent_name = '';
+
/**
* Constructor
*
@@ -33,7 +35,17 @@ class Model {
*/
function Model()
{
- $this->_assign_libraries();
+ // If the magic __get() method is used in a Model references can't be used.
+ $this->_assign_libraries( (method_exists($this, '__get')) ? FALSE : TRUE );
+
+ // We don't want to assign the model object to itself when using the
+ // assign_libraries function below so we'll grab the name of the model parent
+ $methods = get_class_methods($this);
+ if (isset($methods[0]))
+ {
+ $this->_parent_name = $methods[0];
+ }
+
log_message('debug', "Model Class Initialized");
}
@@ -42,17 +54,30 @@ class Model {
*
* Creates local references to all currently instantiated objects
* so that any syntax that can be legally used in a controller
- * can be used within models.
+ * can be used within models.
*
* @access private
*/
- function _assign_libraries()
+ function _assign_libraries($use_reference = TRUE)
{
- $CI =& get_instance();
-
+ $CI =& get_instance();
foreach (array_keys(get_object_vars($CI)) as $key)
{
- $this->$key =& $CI->$key;
+ if ( ! isset($this->$key) AND $key != $this->_parent_name)
+ {
+ // In some cases using references can cause
+ // problems so we'll conditionally use them
+ if ($use_reference == TRUE)
+ {
+ // Needed to prevent reference errors with some configurations
+ $this->$key = '';
+ $this->$key =& $CI->$key;
+ }
+ else
+ {
+ $this->$key = $CI->$key;
+ }
+ }
}
}