From 0ec0e38a297b3fbe73e6e6bc3e26855ad9edbd2b Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Wed, 19 Oct 2022 16:40:58 +0800 Subject: [PATCH] * Refactor the loadModel function to support loading zen files and return zen object. --- framework/base/control.class.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/framework/base/control.class.php b/framework/base/control.class.php index 34a6592f74..149e9ed108 100644 --- a/framework/base/control.class.php +++ b/framework/base/control.class.php @@ -281,9 +281,9 @@ class baseControl global $loadedModels; if(isset($loadedModels[$type][$appName][$moduleName])) { - $this->$objectName = $loadedModels[$type][$appName][$moduleName]; - if($type == 'model') $this->dao = $this->$objectName->dao; - return $this->$objectName; + $this->{$objectName} = $loadedModels[$type][$appName][$moduleName]; + if($type == 'model') $this->dao = $this->{$objectName}->dao; + return $this->{$objectName}; } $modelFile = $this->app->setModelFile($moduleName, $appName, $type); @@ -312,12 +312,18 @@ class baseControl } /** - * 初始化model对象,在control对象中可以通过$this->$objectName来引用。同时将dao对象赋为control对象的成员变量,方便引用。 - * Init the model object thus you can try $this->$objectName to access it. Also assign the $dao object as a member of control object. + * 因为zen继承control,构造函数里会调用loadModel方法,赋默认值值防止递归调用。 */ - $this->$objectName = new $modelClass($appName); - if($type == 'model') $this->dao = $this->$objectName->dao; - $loadedModels[$type][$appName][$moduleName] = $this->$objectName; + if($type == 'zen') $loadedModels[$type][$appName][$moduleName] = false; + + /** + * 初始化model对象,在control对象中可以通过$this->$objectName来引用。同时将dao对象赋为control对象的成员变量,将view对象赋为zen对象的成员变量,方便引用。 + * Init the model object thus you can try $this->$objectName to access it. Also assign the $dao object as a member of control object, assign the $view object as a member of zen object. + */ + $this->{$objectName} = new $modelClass($appName); + if($type == 'model') $this->dao = $this->{$objectName}->dao; + if($type == 'zen') $this->{$objectName}->view = $this->view; + $loadedModels[$type][$appName][$moduleName] = $this->{$objectName}; return $this->$objectName; }