blob: 6f4f7e7efd3537d1add785e5c3e30ed4d60a8dc4 [file] [log] [blame]
adminb0dd10f2006-08-25 17:25:49 +00001<?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.
admine334c472006-10-21 19:44:22 +000010 * @license http://www.codeignitor.com/user_guide/license.html
adminb0dd10f2006-08-25 17:25:49 +000011 * @link http://www.codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
admine334c472006-10-21 19:44:22 +000015
adminb0dd10f2006-08-25 17:25:49 +000016// ------------------------------------------------------------------------
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 */
27class Model {
28
adminc75b09f2006-10-24 00:14:28 +000029 var $_parent_name = '';
30
adminb0dd10f2006-08-25 17:25:49 +000031 /**
32 * Constructor
33 *
34 * @access public
35 */
36 function Model()
37 {
admin1716cb82006-10-25 05:12:34 +000038 // If the magic __get() or __set() methods are used in a Model references can't be used.
admin0e5ca042006-10-27 17:57:30 +000039 $this->_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE );
adminc75b09f2006-10-24 00:14:28 +000040
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
admin57b9e5c2006-10-31 07:11:36 +000043 $this->_parent_name = ucfirst(get_class($this));
adminc75b09f2006-10-24 00:14:28 +000044
adminb0dd10f2006-08-25 17:25:49 +000045 log_message('debug', "Model Class Initialized");
46 }
adminb0dd10f2006-08-25 17:25:49 +000047
48 /**
49 * Assign Libraries
50 *
51 * Creates local references to all currently instantiated objects
admine334c472006-10-21 19:44:22 +000052 * so that any syntax that can be legally used in a controller
adminc75b09f2006-10-24 00:14:28 +000053 * can be used within models.
adminb0dd10f2006-08-25 17:25:49 +000054 *
55 * @access private
56 */
adminc75b09f2006-10-24 00:14:28 +000057 function _assign_libraries($use_reference = TRUE)
adminb0dd10f2006-08-25 17:25:49 +000058 {
adminc75b09f2006-10-24 00:14:28 +000059 $CI =& get_instance();
admin0aef2222006-10-12 18:00:22 +000060 foreach (array_keys(get_object_vars($CI)) as $key)
61 {
adminc75b09f2006-10-24 00:14:28 +000062 if ( ! isset($this->$key) AND $key != $this->_parent_name)
admin57b9e5c2006-10-31 07:11:36 +000063 {
adminc75b09f2006-10-24 00:14:28 +000064 // 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 }
admin0aef2222006-10-12 18:00:22 +000077 }
adminb0dd10f2006-08-25 17:25:49 +000078 }
adminb0dd10f2006-08-25 17:25:49 +000079
80}
81// END Model Class
82?>