diff --git a/engine/Dynamic_properties.php b/engine/Dynamic_properties.php index 4165c0d8..5c8b39bc 100644 --- a/engine/Dynamic_properties.php +++ b/engine/Dynamic_properties.php @@ -5,10 +5,16 @@ trait Dynamic_properties { public function __set(string $key, object $value): void { $this->attributes[$key] = $value; } - + public function __get(string $key) { - if (!isset($this->attributes[$key])) { + if ($key === 'model') { + if (!isset($this->model)) { + require_once 'Model.php'; + $this->model = new Model($this->module_name); + } + return $this->model; + } elseif (!isset($this->attributes[$key])) { $class_name = ucfirst($key); $this->$key = new $key; } diff --git a/engine/Trongate.php b/engine/Trongate.php index 84731b3c..666733be 100755 --- a/engine/Trongate.php +++ b/engine/Trongate.php @@ -3,8 +3,8 @@ class Trongate { use Dynamic_properties; + private $model; protected $modules; - protected $model; protected $url; protected $module_name; protected $parent_module = ''; @@ -13,10 +13,6 @@ class Trongate { public function __construct($module_name=NULL) { $this->module_name = $module_name; $this->modules = new Modules; - - //load the model class - require_once 'Model.php'; - $this->model = new Model($module_name); } public function load($helper) {