From 604e7c9bbad6c977f8b48d0848704dd71ce66cd9 Mon Sep 17 00:00:00 2001 From: coderkun Date: Sun, 22 Sep 2013 21:43:17 +0200 Subject: [PATCH] load Models defined in parent classes --- core/Controller.inc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/Controller.inc b/core/Controller.inc index 2c2309c4..5dd25115 100644 --- a/core/Controller.inc +++ b/core/Controller.inc @@ -328,6 +328,15 @@ if(!is_array($models)) { $models = array($models); } + // Models of parent classes + $parent = $this; + while($parent = get_parent_class($parent)) + { + $properties = get_class_vars($parent); + if(array_key_exists('models', $properties)) { + $models = array_merge($models, $properties['models']); + } + } // Load Models foreach($models as &$model) @@ -337,7 +346,8 @@ Model::load($model); // Construct Model - $this->$model = Model::factory($model); + $modelName = ucfirst(strtolower($model)); + $this->$modelName = Model::factory($model); } catch(\nre\exceptions\ModelNotValidException $e) { if($explicit) {