blob: ebbb0fbe6737611283d280472b11e05ed1c7aa36 [file] [log] [blame]
Derek Allard2067d1a2008-11-13 22:59:24 +00001<?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
8 * @author ExpressionEngine Dev Team
Derek Jones7f3719f2010-01-05 13:35:37 +00009 * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
Derek Allard2067d1a2008-11-13 22:59:24 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://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
24 * @author ExpressionEngine Dev Team
25 * @link http://codeigniter.com/user_guide/libraries/config.html
26 */
Derek Jones8eae4d72010-03-02 13:47:19 -060027class CI_Model {
Derek Allard2067d1a2008-11-13 22:59:24 +000028
29 var $_parent_name = '';
30
31 /**
32 * Constructor
33 *
34 * @access public
35 */
Derek Jones8eae4d72010-03-02 13:47:19 -060036 function CI_Model()
Derek Allard2067d1a2008-11-13 22:59:24 +000037 {
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 );
Barry Mienydd671972010-10-04 16:33:58 +020040
Derek Allard2067d1a2008-11-13 22:59:24 +000041 // 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));
Barry Mienydd671972010-10-04 16:33:58 +020044
Derek Allard2067d1a2008-11-13 22:59:24 +000045 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
Barry Mienydd671972010-10-04 16:33:58 +020053 * can be used within models.
Derek Allard2067d1a2008-11-13 22:59:24 +000054 *
55 * @access private
Barry Mienydd671972010-10-04 16:33:58 +020056 */
Derek Allard2067d1a2008-11-13 22:59:24 +000057 function _assign_libraries($use_reference = TRUE)
58 {
Barry Mienydd671972010-10-04 16:33:58 +020059 $CI =& get_instance();
Derek Allard2067d1a2008-11-13 22:59:24 +000060 foreach (array_keys(get_object_vars($CI)) as $key)
61 {
62 if ( ! isset($this->$key) AND $key != $this->_parent_name)
Barry Mienydd671972010-10-04 16:33:58 +020063 {
Derek Allard2067d1a2008-11-13 22:59:24 +000064 // In some cases using references can cause
65 // problems so we'll conditionally use them
66 if ($use_reference == TRUE)
67 {
Derek Jones8eae4d72010-03-02 13:47:19 -060068 // Needed to prevent reference errors with some configurations
69 $this->$key = '';
Derek Allard2067d1a2008-11-13 22:59:24 +000070 $this->$key =& $CI->$key;
71 }
72 else
73 {
74 $this->$key = $CI->$key;
75 }
76 }
Barry Mienydd671972010-10-04 16:33:58 +020077 }
Derek Allard2067d1a2008-11-13 22:59:24 +000078 }
79
80}
81// END Model Class
82
83/* End of file Model.php */
Derek Jonesc68dfbf2010-03-02 12:59:23 -060084/* Location: ./system/core/Model.php */