webman迁移-优化curd

This commit is contained in:
2026-03-18 15:24:32 +08:00
parent e2ae55319e
commit a64d157388
4 changed files with 31 additions and 11 deletions

View File

@@ -249,8 +249,19 @@ Route::add(
if (!method_exists($class, $action)) {
return new Response(404, ['Content-Type' => 'application/json'], json_encode(['code' => 404, 'msg' => '404 Not Found', 'data' => []], JSON_UNESCAPED_UNICODE));
}
$instance = new $class();
return $instance->$action($request);
// 设置 controller 供 get_controller_path、权限校验等使用
$request->controller = $class;
try {
$instance = new $class();
return $instance->$action($request);
} catch (\Throwable $e) {
return new Response(500, ['Content-Type' => 'application/json'], json_encode([
'code' => 0,
'msg' => $e->getMessage(),
'time' => time(),
'data' => null,
], JSON_UNESCAPED_UNICODE));
}
}
);