This commit is contained in:
2023-04-17 16:05:52 +08:00
parent 4e114754d3
commit 7e71c737d5
+16 -20
View File
@@ -67,21 +67,15 @@ namespace {$namespace};
exit(); exit();
} }
} else { } else {
$import = "use Kiri; $import = "use Exception;
use Exception;
use Kiri\Annotation\Target;
use Kiri\Annotation\Route\Middleware;
use Kiri\Annotation\Route\Route;
use Kiri\Annotation\Route\RequestMethod;
use Kiri\Core\Str; use Kiri\Core\Str;
use Kiri\Core\Json; use Kiri\Core\Json;
use Kiri\Message\Handler\CoreMiddleware; use Kiri\Router\Base\Controller;
use Components\Middleware\OAuthMiddleware;
use Kiri\Message\Handler\Controller;
use {$model_namespace}\\{$managerName}; use {$model_namespace}\\{$managerName};
use Kiri\Router\Validator\BindForm; use Kiri\Router\Validator\BindForm;
use Kiri\Router\Validator\Validator; use Kiri\Router\Validator\Validator;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Kiri\Router\Annotate\AutoController;
"; ";
} }
@@ -103,7 +97,7 @@ use Psr\Http\Message\ResponseInterface;
* *
* @package controller * @package controller
*/ */
#[Target] class {$controllerName}Controller extends Controller #[AutoController] class {$controllerName}Controller extends Controller
{ {
"; ";
@@ -211,9 +205,11 @@ use Psr\Http\Message\ResponseInterface;
$_path = ltrim($_path, '/'); $_path = ltrim($_path, '/');
$this->getData($className, $fields);
return ' return '
/** /**
* @return string * @return ResponseInterface
* @throws Exception * @throws Exception
*/ */
public function actionAdd(#[BindForm(' . $className . 'Form::class)] Validator $form): ResponseInterface public function actionAdd(#[BindForm(' . $className . 'Form::class)] Validator $form): ResponseInterface
@@ -222,7 +218,7 @@ use Psr\Http\Message\ResponseInterface;
return $this->response->json([\'code\' => 500, \'message\' => $form->error()]); return $this->response->json([\'code\' => 500, \'message\' => $form->error()]);
} }
$model = new ' . $className . '(); $model = new ' . $className . '();
$model->attributes = $' . lcfirst($className) . 'Form->getFormData()->toArray(); $model->attributes = $form->getFormData()->toArray();
if (!$model->save()) { if (!$model->save()) {
return $this->response->json([\'code\' => 500, \'message\' => $model->getLastError()]); return $this->response->json([\'code\' => 500, \'message\' => $model->getLastError()]);
} else { } else {
@@ -236,7 +232,7 @@ use Psr\Http\Message\ResponseInterface;
{ {
return ' return '
/** /**
* @return string * @return ResponseInterface
* @throws Exception * @throws Exception
*/ */
public function actionAuditing(): ResponseInterface public function actionAuditing(): ResponseInterface
@@ -258,7 +254,7 @@ use Psr\Http\Message\ResponseInterface;
{ {
return ' return '
/** /**
* @return string * @return ResponseInterface
* @throws Exception * @throws Exception
*/ */
public function actionBatchAuditing(): ResponseInterface public function actionBatchAuditing(): ResponseInterface
@@ -293,7 +289,7 @@ use Psr\Http\Message\ResponseInterface;
return ' return '
/** /**
* @return string * @return ResponseInterface
* @throws Exception * @throws Exception
*/ */
public function actionUpdate(#[BindForm(' . $className . 'Form::class)] Validator $form): ResponseInterface public function actionUpdate(#[BindForm(' . $className . 'Form::class)] Validator $form): ResponseInterface
@@ -305,7 +301,7 @@ use Psr\Http\Message\ResponseInterface;
if (empty($model)) { if (empty($model)) {
return $this->response->json([\'code\' => 500, \'message\' => SELECT_IS_NULL]); return $this->response->json([\'code\' => 500, \'message\' => SELECT_IS_NULL]);
} }
$model->attributes = $this->loadParam(); $model->attributes = $form->getFormData()->toArray();
if (!$model->save()) { if (!$model->save()) {
return $this->response->json([\'code\' => 500, \'message\' => $model->getLastError()]); return $this->response->json([\'code\' => 500, \'message\' => $model->getLastError()]);
} else { } else {
@@ -331,7 +327,7 @@ use Psr\Http\Message\ResponseInterface;
return ' return '
/** /**
* @return string * @return ResponseInterface
* @throws Exception * @throws Exception
*/ */
public function actionBatchDelete(): ResponseInterface public function actionBatchDelete(): ResponseInterface
@@ -367,7 +363,7 @@ use Psr\Http\Message\ResponseInterface;
return ' return '
/** /**
* @return string * @return ResponseInterface
* @throws Exception * @throws Exception
*/ */
public function actionDetail(): ResponseInterface public function actionDetail(): ResponseInterface
@@ -398,7 +394,7 @@ use Psr\Http\Message\ResponseInterface;
return ' return '
/** /**
* @return string * @return ResponseInterface
* @throws Exception * @throws Exception
*/ */
public function actionDelete(): ResponseInterface public function actionDelete(): ResponseInterface
@@ -434,7 +430,7 @@ use Psr\Http\Message\ResponseInterface;
$_path = ltrim($_path, '/'); $_path = ltrim($_path, '/');
return ' return '
/** /**
* @return string * @return ResponseInterface
* @throws Exception * @throws Exception
*/ */
public function actionList(): ResponseInterface public function actionList(): ResponseInterface