PageRenderTime 75ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/system/libraries/Model.php

https://github.com/bwghughes/houghandco
PHP | 82 lines | 30 code | 8 blank | 44 comment | 5 complexity | 2c61fbfa34e9896028ab1318f0cba071 MD5 | raw file
  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
  8. * @author ExpressionEngine Dev Team
  9. * @copyright Copyright (c) 2006, EllisLab, Inc.
  10. * @license http://codeigniter.com/user_guide/license.html
  11. * @link http://codeigniter.com
  12. * @since Version 1.0
  13. * @filesource
  14. */
  15. // ------------------------------------------------------------------------
  16. /**
  17. * CodeIgniter Model Class
  18. *
  19. * @package CodeIgniter
  20. * @subpackage Libraries
  21. * @category Libraries
  22. * @author ExpressionEngine Dev Team
  23. * @link http://codeigniter.com/user_guide/libraries/config.html
  24. */
  25. class Model {
  26. var $_parent_name = '';
  27. /**
  28. * Constructor
  29. *
  30. * @access public
  31. */
  32. function Model()
  33. {
  34. // If the magic __get() or __set() methods are used in a Model references can't be used.
  35. $this->_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE );
  36. // We don't want to assign the model object to itself when using the
  37. // assign_libraries function below so we'll grab the name of the model parent
  38. $this->_parent_name = ucfirst(get_class($this));
  39. log_message('debug', "Model Class Initialized");
  40. }
  41. /**
  42. * Assign Libraries
  43. *
  44. * Creates local references to all currently instantiated objects
  45. * so that any syntax that can be legally used in a controller
  46. * can be used within models.
  47. *
  48. * @access private
  49. */
  50. function _assign_libraries($use_reference = TRUE)
  51. {
  52. $CI =& get_instance();
  53. foreach (array_keys(get_object_vars($CI)) as $key)
  54. {
  55. if ( ! isset($this->$key) AND $key != $this->_parent_name)
  56. {
  57. // In some cases using references can cause
  58. // problems so we'll conditionally use them
  59. if ($use_reference == TRUE)
  60. {
  61. // Needed to prevent reference errors with some configurations
  62. $this->$key = '';
  63. $this->$key =& $CI->$key;
  64. }
  65. else
  66. {
  67. $this->$key = $CI->$key;
  68. }
  69. }
  70. }
  71. }
  72. }
  73. // END Model Class
  74. ?>