Model.php

Go to the documentation of this file.
00001 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
00002 /**
00003  * CodeIgniter
00004  *
00005  * An open source application development framework for PHP 4.3.2 or newer
00006  *
00007  * @package             CodeIgniter
00008  * @author              ExpressionEngine Dev Team
00009  * @copyright   Copyright (c) 2006, EllisLab, Inc.
00010  * @license             http://codeigniter.com/user_guide/license.html
00011  * @link                http://codeigniter.com
00012  * @since               Version 1.0
00013  * @filesource
00014  */
00015 
00016 // ------------------------------------------------------------------------
00017 
00018 /**
00019  * CodeIgniter Model Class
00020  *
00021  * @package             CodeIgniter
00022  * @subpackage  Libraries
00023  * @category    Libraries
00024  * @author              ExpressionEngine Dev Team
00025  * @link                http://codeigniter.com/user_guide/libraries/config.html
00026  */
00027 class Model {
00028 
00029         var $_parent_name = '';
00030 
00031         /**
00032          * Constructor
00033          *
00034          * @access public
00035          */
00036         function Model()
00037         {
00038                 // If the magic __get() or __set() methods are used in a Model references can't be used.
00039                 $this->_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE );
00040                 
00041                 // We don't want to assign the model object to itself when using the
00042                 // assign_libraries function below so we'll grab the name of the model parent
00043                 $this->_parent_name = ucfirst(get_class($this));
00044                 
00045                 log_message('debug', "Model Class Initialized");
00046         }
00047 
00048         /**
00049          * Assign Libraries
00050          *
00051          * Creates local references to all currently instantiated objects
00052          * so that any syntax that can be legally used in a controller
00053          * can be used within models.  
00054          *
00055          * @access private
00056          */     
00057         function _assign_libraries($use_reference = TRUE)
00058         {
00059                 $CI =& get_instance();                          
00060                 foreach (array_keys(get_object_vars($CI)) as $key)
00061                 {
00062                         if ( ! isset($this->$key) AND $key != $this->_parent_name)
00063                         {                       
00064                                 // In some cases using references can cause
00065                                 // problems so we'll conditionally use them
00066                                 if ($use_reference == TRUE)
00067                                 {
00068                                         // Needed to prevent reference errors with some configurations
00069                                         $this->$key = '';
00070                                         $this->$key =& $CI->$key;
00071                                 }
00072                                 else
00073                                 {
00074                                         $this->$key = $CI->$key;
00075                                 }
00076                         }
00077                 }               
00078         }
00079 
00080 }
00081 // END Model Class
00082 
00083 /* End of file Model.php */
00084 /* Location: ./system/libraries/Model.php */