Changeset 1276
- Timestamp:
- 11/26/2007 12:29:22 PM (12 months ago)
- Files:
-
- 1 modified
-
trunk/system/libraries/ORM.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/libraries/ORM.php
r1271 r1276 16 16 protected static $db; 17 17 18 // Automatic saving on model destruction 19 protected $auto_save = FALSE; 20 18 21 // This table 19 22 protected $class; … … 89 92 90 93 /** 91 * Magic method for getting object keys. 94 * Enables automatic saving of the object when the model is destroyed. 95 */ 96 public function __destruct() 97 { 98 if ($this->auto_save == TRUE) 99 { 100 // Automatically save the model 101 $this->save(); 102 } 103 } 104 105 /** 106 * Magic method for getting object and model keys. 92 107 */ 93 108 public function __get($key) … … 97 112 return $this->object->$key; 98 113 } 99 elseif ($key === 'table_name') 100 { 101 return $this->table; 102 } 103 elseif ($key === 'class_name') 104 { 105 return $this->class; 106 } 107 } 108 109 /** 110 * Magic method for setting object keys. 114 else 115 { 116 switch($key) 117 { 118 case 'table_name': 119 return $this->table; 120 break; 121 case 'class_name': 122 return $this->class; 123 break; 124 case 'auto_save': 125 return $this->auto_save; 126 break; 127 } 128 } 129 } 130 131 /** 132 * Magic method for setting object and model keys. 111 133 */ 112 134 public function __set($key, $value) … … 121 143 // Data has changed 122 144 $this->changed[$key] = $key; 145 } 146 } 147 else 148 { 149 switch($key) 150 { 151 case 'auto_save': 152 $this->auto_save = (bool) $value; 153 break; 123 154 } 124 155 }
