mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
增加APP_MULTI_MODULE常量 用于设置是否多模块设计
This commit is contained in:
1
base.php
1
base.php
@@ -36,6 +36,7 @@ defined('EXT') or define('EXT', '.php');
|
||||
defined('MODEL_LAYER') or define('MODEL_LAYER', 'model');
|
||||
defined('VIEW_LAYER') or define('VIEW_LAYER', 'view');
|
||||
defined('CONTROLLER_LAYER') or define('CONTROLLER_LAYER', 'controller');
|
||||
defined('APP_MULTI_MODULE') or define('APP_MULTI_MODULE', true); // 是否多模块
|
||||
defined('APP_DEBUG') or define('APP_DEBUG', false); // 是否调试模式
|
||||
defined('APP_HOOK') or define('APP_HOOK', false); // 是否开启HOOK
|
||||
defined('ENV_PREFIX') or define('ENV_PREFIX', 'T_'); // 环境变量的配置前缀
|
||||
|
||||
@@ -195,7 +195,7 @@ class App
|
||||
private static function initModule($module, $config)
|
||||
{
|
||||
// 定位模块目录
|
||||
$module = COMMON_MODULE == $module ? '' : $module . DS;
|
||||
$module = (COMMON_MODULE == $module || !APP_MULTI_MODULE) ? '' : $module . DS;
|
||||
|
||||
// 加载初始化文件
|
||||
if (is_file(APP_PATH . $module . 'init' . EXT)) {
|
||||
@@ -323,8 +323,8 @@ class App
|
||||
}
|
||||
}
|
||||
|
||||
$module = strtolower($result[0] ?: $config['default_module']);
|
||||
if ($module) {
|
||||
if (APP_MULTI_MODULE) {
|
||||
$module = strtolower($result[0] ?: $config['default_module']);
|
||||
if ($maps = $config['url_module_map']) {
|
||||
if (isset($maps[$module])) {
|
||||
// 记录当前别名
|
||||
|
||||
@@ -65,6 +65,7 @@ class Build
|
||||
// 创建模块
|
||||
protected static function buildModule($module, $list)
|
||||
{
|
||||
$module = APP_MULTI_MODULE ? $module : '';
|
||||
if (!is_dir(APP_PATH . $module)) {
|
||||
// 创建模块目录
|
||||
mkdir(APP_PATH . $module);
|
||||
|
||||
@@ -398,6 +398,6 @@ class Loader
|
||||
*/
|
||||
public static function parseClass($module, $layer, $name)
|
||||
{
|
||||
return APP_NAMESPACE . '\\' . ($module ? $module . '\\' : '') . $layer . '\\' . self::parseName(str_replace('/', '\\', $name), 1);
|
||||
return APP_NAMESPACE . '\\' . (APP_MULTI_MODULE ? $module . '\\' : '') . $layer . '\\' . self::parseName(str_replace('/', '\\', $name), 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,13 +467,13 @@ class Route
|
||||
}
|
||||
// 解析[模块/控制器/操作]
|
||||
if ($reverse) {
|
||||
$module = array_shift($path);
|
||||
$module = APP_MULTI_MODULE ? array_shift($path) : null;
|
||||
$controller = !empty($path) ? array_shift($path) : null;
|
||||
$action = !empty($path) ? array_shift($path) : null;
|
||||
} else {
|
||||
$action = array_pop($path);
|
||||
$controller = !empty($path) ? array_pop($path) : null;
|
||||
$module = !empty($path) ? array_pop($path) : null;
|
||||
$module = APP_MULTI_MODULE && !empty($path) ? array_pop($path) : null;
|
||||
}
|
||||
$action = '[rest]' == $action ? REQUEST_METHOD : $action;
|
||||
$route = [$module, $controller, $action];
|
||||
|
||||
@@ -52,7 +52,7 @@ class Url
|
||||
if (!defined('BIND_CONTROLLER')) {
|
||||
$var['controller'] = !empty($path) ? array_pop($path) : CONTROLLER_NAME;
|
||||
}
|
||||
if (!defined('BIND_MODULE')) {
|
||||
if (APP_MULTI_MODULE && !defined('BIND_MODULE')) {
|
||||
if (!empty($path)) {
|
||||
$var['module'] = array_pop($path);
|
||||
} elseif (MODULE_NAME) {
|
||||
|
||||
@@ -250,7 +250,7 @@ class View
|
||||
} elseif (Cookie::get('think_theme')) {
|
||||
$theme = Cookie::get('think_theme');
|
||||
}
|
||||
if (!is_dir(APP_PATH . ($module ? $module . DS : '') . $this->config['view_layer'] . DS . $theme)) {
|
||||
if (!is_dir(APP_PATH . (APP_MULTI_MODULE ? $module . DS : '') . $this->config['view_layer'] . DS . $theme)) {
|
||||
$theme = $this->config['default_theme'];
|
||||
}
|
||||
Cookie::set('think_theme', $theme, 864000);
|
||||
@@ -276,7 +276,7 @@ class View
|
||||
$tmplPath = $this->config['view_path']; // 模块设置独立的视图目录
|
||||
if (!$tmplPath) {
|
||||
// 定义TMPL_PATH 则改变全局的视图目录到模块之外
|
||||
$tmplPath = defined('TMPL_PATH') ? TMPL_PATH . $module . DS : APP_PATH . ($module ? $module . DS : '') . $this->config['view_layer'] . DS;
|
||||
$tmplPath = defined('TMPL_PATH') ? TMPL_PATH . $module . DS : APP_PATH . (APP_MULTI_MODULE ? $module . DS : '') . $this->config['view_layer'] . DS;
|
||||
}
|
||||
return $tmplPath . $theme;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user