* Add comment.

This commit is contained in:
liugang
2019-08-09 16:15:34 +08:00
parent 90422eb0e8
commit 9cf4d28a79
3 changed files with 18 additions and 90 deletions
+5 -50
View File
@@ -21,10 +21,10 @@ include dirname(__FILE__) . '/base/control.class.php';
class control extends baseControl
{
/**
* 加载指定模块的model文件。
* Load the model file of one module.
*
* Extension: set appName as empty.
* 企业版部分功能是从然之合并过来的。然之代码中调用loadModel方法时传递了一个非空的appName,在禅道中会导致错误。
* 调用父类的loadModel方法来避免这个错误。
* Some codes merged from ranzhi called the function loadModel with a non-empty appName which causes an error in zentao.
* Call the parent function with empty appName to avoid this error.
*
* @param string $moduleName 模块名,如果为空,使用当前模块。The module name, if empty, use current module's name.
* @param string $appName The app name, if empty, use current app's name.
@@ -33,52 +33,7 @@ class control extends baseControl
*/
public function loadModel($moduleName = '', $appName = '')
{
$appName = '';
if(empty($moduleName)) $moduleName = $this->moduleName;
if(empty($appName)) $appName = $this->appName;
global $loadedModels;
if(isset($loadedModels[$appName][$moduleName]))
{
$this->$moduleName = $loadedModels[$appName][$moduleName];
$this->dao = $this->$moduleName->dao;
return $this->$moduleName;
}
$modelFile = $this->app->setModelFile($moduleName, $appName);
/**
* 如果没有model文件,尝试加载config配置信息。
* If no model file, try load config.
*/
if(!helper::import($modelFile))
{
$this->app->loadModuleConfig($moduleName, $appName);
$this->app->loadLang($moduleName, $appName);
$this->dao = new dao();
return false;
}
/**
* 如果没有扩展文件,model类名是$moduleName + 'model',如果有扩展,还需要增加ext前缀。
* If no extension file, model class name is $moduleName + 'model', else with 'ext' as the prefix.
*/
$modelClass = class_exists('ext' . $appName . $moduleName. 'model') ? 'ext' . $appName . $moduleName . 'model' : $appName . $moduleName . 'model';
if(!class_exists($modelClass))
{
$modelClass = class_exists('ext' . $moduleName. 'model') ? 'ext' . $moduleName . 'model' : $moduleName . 'model';
if(!class_exists($modelClass)) $this->app->triggerError(" The model $modelClass not found", __FILE__, __LINE__, $exit = true);
}
/**
* 初始化model对象,在control对象中可以通过$this->$moduleName来引用。同时将dao对象赋为control对象的成员变量,方便引用。
* Init the model object thus you can try $this->$moduleName to access it. Also assign the $dao object as a member of control object.
*/
$loadedModels[$appName][$moduleName] = new $modelClass($appName);
$this->$moduleName = $loadedModels[$appName][$moduleName];
$this->dao = $this->$moduleName->dao;
return $this->$moduleName;
return parent::loadModel($moduleName);
}
/**
+5 -31
View File
@@ -21,12 +21,10 @@ include dirname(__FILE__) . '/base/model.class.php';
class model extends baseModel
{
/**
* 加载一个模块的model。加载完成后,使用$this->$moduleName来访问这个model对象。
* 比如:loadModel('user')引入user模块的model实例对象,可以通过$this->user来访问它。
*
* Load the model of one module. After loaded, can use $this->$moduleName to visit the model object.
*
* Extension: set appName as empty.
* 企业版部分功能是从然之合并过来的。然之代码中调用loadModel方法时传递了一个非空的appName,在禅道中会导致错误。
* 调用父类的loadModel方法来避免这个错误。
* Some codes merged from ranzhi called the function loadModel with a non-empty appName which causes an error in zentao.
* Call the parent function with empty appName to avoid this error.
*
* @param string $moduleName
* @access public
@@ -34,31 +32,7 @@ class model extends baseModel
*/
public function loadModel($moduleName, $appName = '')
{
$appName = '';
if(empty($moduleName)) return false;
if(empty($appName)) $appName = $this->appName;
global $loadedModels;
if(isset($loadedModels[$appName][$moduleName]))
{
$this->$moduleName = $loadedModels[$appName][$moduleName];
return $this->$moduleName;
}
$modelFile = $this->app->setModelFile($moduleName, $appName);
if(!helper::import($modelFile)) return false;
$modelClass = class_exists('ext' . $appName . $moduleName. 'model') ? 'ext' . $appName . $moduleName . 'model' : $appName . $moduleName . 'model';
if(!class_exists($modelClass))
{
$modelClass = class_exists('ext' . $moduleName. 'model') ? 'ext' . $moduleName . 'model' : $moduleName . 'model';
if(!class_exists($modelClass)) $this->app->triggerError(" The model $modelClass not found", __FILE__, __LINE__, $exit = true);
}
$loadedModels[$appName][$moduleName] = new $modelClass($appName);
$this->$moduleName = $loadedModels[$appName][$moduleName];
return $this->$moduleName;
return parent::loadModel($moduleName);
}
/**
+8 -9
View File
@@ -66,8 +66,10 @@ class router extends baseRouter
}
/**
* 加载语言文件,返回全局$lang对象。
* Load lang and return it as the global lang object.
* 企业版部分功能是从然之合并过来的。然之代码中调用loadLang方法时传递了一个非空的appName,在禅道中会导致错误。
* 把appName设置为空来避免这个错误。
* Some codes merged from ranzhi called the function loadLang with a non-empty appName which causes an error in zentao.
* Set the value of appName to empty to avoid this error.
*
* @param string $moduleName the module name
* @param string $appName the app name
@@ -176,13 +178,10 @@ class router extends baseRouter
}
/**
* 加载模块的config文件,返回全局$config对象。
* 如果该模块是common,加载$configRoot的配置文件,其他模块则加载其模块的配置文件。
*
* Load config and return it as the global config object.
* If the module is common, search in $configRoot, else in $modulePath.
*
* Extension: set appName as empty.
* 企业版部分功能是从然之合并过来的。然之代码中调用loadModuleConfig方法时传递了一个非空的appName,在禅道中会导致错误。
* 把appName设置为空来避免这个错误。
* Some codes merged from ranzhi called the function loadModuleConfig with a non-empty appName which causes an error in zentao.
* Set the value of appName to empty to avoid this error.
*
* @param string $moduleName module name
* @param string $appName app name