This commit is contained in:
2023-04-11 16:40:59 +08:00
parent 65e0c84b65
commit 47ab82628b
2 changed files with 32 additions and 15 deletions
+1 -1
View File
@@ -180,7 +180,7 @@ class Gii
*/ */
private function generateController(array $data): string private function generateController(array $data): string
{ {
$controller = new GiiController($data['classFileName'], $data['fields']); $controller = new GiiController($data['classFileName'], $data['fields'], $data['tableName']);
$controller->setConnection($this->db); $controller->setConnection($this->db);
$controller->setModelPath($this->modelPath); $controller->setModelPath($this->modelPath);
$controller->setInput($this->input); $controller->setInput($this->input);
+31 -14
View File
@@ -26,10 +26,11 @@ class GiiController extends GiiBase
* @param $className * @param $className
* @param $fields * @param $fields
*/ */
public function __construct($className, $fields) public function __construct($className, $fields, $tableName)
{ {
$this->className = $className; $this->className = $className;
$this->fields = $fields; $this->fields = $fields;
$this->tableName = $tableName;
} }
@@ -122,20 +123,36 @@ use {$model_namespace}\\{$managerName};
$html .= ' $html .= '
}'; }';
$tableName = str_replace('_', '-', $this->input->getOption('table')); $file = APP_PATH . 'routes/' . $this->input->getOption('database') . '.php';
if (!file_exists($file)) {
touch($file);
file_put_contents($file, '<?php' . PHP_EOL);
file_put_contents($file, PHP_EOL, FILE_APPEND);
file_put_contents($file, PHP_EOL, FILE_APPEND);
file_put_contents($file, PHP_EOL, FILE_APPEND);
file_put_contents($file, 'use Kiri\Message\Handler\Router;' . PHP_EOL, FILE_APPEND);
file_put_contents($file, PHP_EOL, FILE_APPEND);
file_put_contents($file, PHP_EOL, FILE_APPEND);
file_put_contents($file, PHP_EOL, FILE_APPEND);
}
Kiri::getLogger()->debug('add Route:'); $tableName = str_replace($this->db->tablePrefix, '', $this->tableName);
Kiri::getLogger()->debug(' $tableName = str_replace('_', '-', $tableName);
Router::group([\'prefix\' => \'' . $tableName . '\'], function () {
Router::post(\'add\', \'' . $controllerName . 'Controller@actionAdd\'); $addRouter = 'Router::group([\'prefix\' => \'' . $tableName . '\',\'namespace\' => \''.$namespace.'\'], function () {
Router::get(\'list\', \'' . $controllerName . 'Controller@actionList\'); Router::post(\'add\', \'' . $controllerName . 'Controller@actionAdd\');
Router::post(\'update\', \'' . $controllerName . 'Controller@actionUpdate\'); Router::get(\'list\', \'' . $controllerName . 'Controller@actionList\');
Router::post(\'auditing\', \'' . $controllerName . 'Controller@actionAuditing\'); Router::post(\'update\', \'' . $controllerName . 'Controller@actionUpdate\');
Router::post(\'batch-auditing\', \'' . $controllerName . 'Controller@actionBatchAuditing\'); Router::post(\'auditing\', \'' . $controllerName . 'Controller@actionAuditing\');
Router::post(\'batch-delete\', \'' . $controllerName . 'Controller@actionBatchDelete\'); Router::post(\'batch-auditing\', \'' . $controllerName . 'Controller@actionBatchAuditing\');
Router::post(\'delete\', \'' . $controllerName . 'Controller@actionDelete\'); Router::post(\'batch-delete\', \'' . $controllerName . 'Controller@actionBatchDelete\');
Router::get(\'detail\', \'' . $controllerName . 'Controller@actionDetail\'); Router::post(\'delete\', \'' . $controllerName . 'Controller@actionDelete\');
});'); Router::get(\'detail\', \'' . $controllerName . 'Controller@actionDetail\');
});
';
if (!str_contains(preg_replace('/\s/ixm', '', file_get_contents($file)), preg_replace('/\s/ixm', '', $addRouter))) {
file_put_contents($file, $addRouter, FILE_APPEND);
}
$file = $path['path'] . '/' . $controllerName . 'Controller.php'; $file = $path['path'] . '/' . $controllerName . 'Controller.php';
if (file_exists($file)) { if (file_exists($file)) {