From f1c45ca5e2a7258fc1cffc658911e0bfae949211 Mon Sep 17 00:00:00 2001 From: walkor Date: Thu, 8 Dec 2022 17:50:12 +0800 Subject: [PATCH] save --- .../admin/app/controller/TableController.php | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/plugin/admin/app/controller/TableController.php b/src/plugin/admin/app/controller/TableController.php index 7237939..1fe5420 100644 --- a/src/plugin/admin/app/controller/TableController.php +++ b/src/plugin/admin/app/controller/TableController.php @@ -399,10 +399,10 @@ class TableController extends Base $title = $request->post('title'); $pid = $request->post('pid', 0); $icon = $request->post('icon', ''); - $controller_file = trim($request->post('controller', ''), '/'); - $model_file = trim($request->post('model', ''), ''); + $controller_file = '/' . trim($request->post('controller', ''), '/'); + $model_file = '/' . trim($request->post('model', ''), ''); $overwrite = $request->post('overwrite'); - if (!$controller_file || !$model_file) { + if ($controller_file === '/' || $model_file === '/') { return $this->json(1, '控制器和model不能为空'); } @@ -427,28 +427,29 @@ class TableController extends Base } if (!$overwrite) { - if (is_file($controller_file)) { + if (is_file(base_path($controller_file))) { return $this->json(1, "/$controller_file 已经存在"); } - if (is_file($model_file)) { + if (is_file(base_path($model_file))) { return $this->json(1, "/$model_file 已经存在"); } } + $plugin = ''; + if (strpos($controller_file, '/plugin/') === 0) { + echo "innn?"; + if (!preg_match('/^\/plugin\/(.*?)\//', $controller_file, $match)) { + return $this->json(2, '参数非法'); + } + $plugin = $match[1]; + } + $model_class = $model_file_name; $model_namespace = str_replace('/' , '\\', trim($model_path, '/')); // 创建model $this->createModel($model_class, $model_namespace, base_path($model_file), $table_name); - $plugin = ''; - if (strpos('/plugin/', $controller_file) === 0) { - if (!preg_match('/\/plugin\/(.*?)\//', $controller_file, $match)) { - return $this->json(2, '参数非法'); - } - $plugin = $match[1]; - } - $controller_suffix = $plugin ? config("plugin.$plugin.app.controller_suffix") : config('app.controller_suffix'); $controller_class = $controller_file_name; $controller_namespace = str_replace('/' , '\\', trim($controller_path, '/')); @@ -456,6 +457,7 @@ class TableController extends Base $controller_url_name = $controller_suffix && substr($controller_class, -strlen($controller_suffix)) === $controller_suffix ? substr($controller_class, 0, -strlen($controller_suffix)) : $controller_class; $controller_url_name = str_replace('_', '-', $inflector->tableize($controller_url_name)); $explode = explode('/', trim(strtolower($controller_path), '/')); + if ($plugin) { array_splice($explode, 0, 2); } @@ -465,6 +467,7 @@ class TableController extends Base unset($explode[$index]); } } + $controller_base = implode('/', $explode); $controller_class_with_namespace = "$controller_namespace\\$controller_class"; $template_path = $controller_base ? "$controller_base/$controller_url_name" : $controller_url_name; @@ -474,7 +477,7 @@ class TableController extends Base $template_file_path = ($plugin ? "/plugin/$plugin" : '') . "/app/view/$template_path"; $model_class_with_namespace = "$model_namespace\\$model_class"; $primary_key = (new $model_class_with_namespace)->getKeyName(); - $url_path_base = $plugin ? "/app/$plugin" : '/'; + $url_path_base = $plugin ? "/app/$plugin/" : '/'; $this->createTemplate(base_path($template_file_path), $table_name, $template_path, $url_path_base, $primary_key, "$controller_namespace\\$controller_class"); $menu = Rule::where('key', $controller_class_with_namespace)->first();