admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * Code Igniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 4.3.2 or newer |
| 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author Rick Ellis |
| 9 | * @copyright Copyright (c) 2006, pMachine, Inc. |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 10 | * @license http://www.codeignitor.com/user_guide/license.html |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 11 | * @link http://www.codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 15 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * Code Igniter Model Class |
| 20 | * |
| 21 | * @package CodeIgniter |
| 22 | * @subpackage Libraries |
| 23 | * @category Libraries |
| 24 | * @author Rick Ellis |
| 25 | * @link http://www.codeigniter.com/user_guide/libraries/config.html |
| 26 | */ |
| 27 | class Model { |
| 28 | |
admin | c75b09f | 2006-10-24 00:14:28 +0000 | [diff] [blame] | 29 | var $_parent_name = ''; |
| 30 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 31 | /** |
| 32 | * Constructor |
| 33 | * |
| 34 | * @access public |
| 35 | */ |
| 36 | function Model() |
| 37 | { |
admin | 1716cb8 | 2006-10-25 05:12:34 +0000 | [diff] [blame] | 38 | // If the magic __get() or __set() methods are used in a Model references can't be used. |
admin | 0e5ca04 | 2006-10-27 17:57:30 +0000 | [diff] [blame] | 39 | $this->_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE ); |
admin | c75b09f | 2006-10-24 00:14:28 +0000 | [diff] [blame] | 40 | |
| 41 | // We don't want to assign the model object to itself when using the |
| 42 | // assign_libraries function below so we'll grab the name of the model parent |
admin | 57b9e5c | 2006-10-31 07:11:36 +0000 | [diff] [blame^] | 43 | $this->_parent_name = ucfirst(get_class($this)); |
admin | c75b09f | 2006-10-24 00:14:28 +0000 | [diff] [blame] | 44 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 45 | log_message('debug', "Model Class Initialized"); |
| 46 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * Assign Libraries |
| 50 | * |
| 51 | * Creates local references to all currently instantiated objects |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 52 | * so that any syntax that can be legally used in a controller |
admin | c75b09f | 2006-10-24 00:14:28 +0000 | [diff] [blame] | 53 | * can be used within models. |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 54 | * |
| 55 | * @access private |
| 56 | */ |
admin | c75b09f | 2006-10-24 00:14:28 +0000 | [diff] [blame] | 57 | function _assign_libraries($use_reference = TRUE) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 58 | { |
admin | c75b09f | 2006-10-24 00:14:28 +0000 | [diff] [blame] | 59 | $CI =& get_instance(); |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 60 | foreach (array_keys(get_object_vars($CI)) as $key) |
| 61 | { |
admin | c75b09f | 2006-10-24 00:14:28 +0000 | [diff] [blame] | 62 | if ( ! isset($this->$key) AND $key != $this->_parent_name) |
admin | 57b9e5c | 2006-10-31 07:11:36 +0000 | [diff] [blame^] | 63 | { |
admin | c75b09f | 2006-10-24 00:14:28 +0000 | [diff] [blame] | 64 | // In some cases using references can cause |
| 65 | // problems so we'll conditionally use them |
| 66 | if ($use_reference == TRUE) |
| 67 | { |
| 68 | // Needed to prevent reference errors with some configurations |
| 69 | $this->$key = ''; |
| 70 | $this->$key =& $CI->$key; |
| 71 | } |
| 72 | else |
| 73 | { |
| 74 | $this->$key = $CI->$key; |
| 75 | } |
| 76 | } |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 77 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 78 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 79 | |
| 80 | } |
| 81 | // END Model Class |
| 82 | ?> |