Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
| 2 | /**
|
| 3 | * CodeIgniter
|
| 4 | *
|
| 5 | * An open source application development framework for PHP 4.3.2 or newer
|
| 6 | *
|
| 7 | * @package CodeIgniter
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 8 | * @author ExpressionEngine Dev Team
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2006, EllisLab, Inc.
|
Derek Allard | 6838f00 | 2007-10-04 19:29:59 +0000 | [diff] [blame] | 10 | * @license http://www.codeigniter.com/user_guide/license.html
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 11 | * @link http://www.codeigniter.com
|
| 12 | * @since Version 1.0
|
| 13 | * @filesource
|
| 14 | */
|
| 15 |
|
| 16 | // ------------------------------------------------------------------------
|
| 17 |
|
| 18 | /**
|
| 19 | * CodeIgniter Model Class
|
| 20 | *
|
| 21 | * @package CodeIgniter
|
| 22 | * @subpackage Libraries
|
| 23 | * @category Libraries
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 24 | * @author ExpressionEngine Dev Team
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 25 | * @link http://www.codeigniter.com/user_guide/libraries/config.html
|
| 26 | */
|
| 27 | class Model {
|
| 28 |
|
| 29 | var $_parent_name = '';
|
| 30 |
|
| 31 | /**
|
| 32 | * Constructor
|
| 33 | *
|
| 34 | * @access public
|
| 35 | */
|
| 36 | function Model()
|
| 37 | {
|
| 38 | // If the magic __get() or __set() methods are used in a Model references can't be used.
|
| 39 | $this->_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE );
|
| 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
|
| 43 | $this->_parent_name = ucfirst(get_class($this));
|
| 44 |
|
| 45 | log_message('debug', "Model Class Initialized");
|
| 46 | }
|
| 47 |
|
| 48 | /**
|
| 49 | * Assign Libraries
|
| 50 | *
|
| 51 | * Creates local references to all currently instantiated objects
|
| 52 | * so that any syntax that can be legally used in a controller
|
| 53 | * can be used within models.
|
| 54 | *
|
| 55 | * @access private
|
| 56 | */
|
| 57 | function _assign_libraries($use_reference = TRUE)
|
| 58 | {
|
| 59 | $CI =& get_instance();
|
| 60 | foreach (array_keys(get_object_vars($CI)) as $key)
|
| 61 | {
|
| 62 | if ( ! isset($this->$key) AND $key != $this->_parent_name)
|
| 63 | {
|
| 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 | }
|
| 77 | }
|
| 78 | }
|
| 79 |
|
| 80 | }
|
| 81 | // END Model Class
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 82 | ?> |