This commit is contained in:
2021-09-29 10:49:47 +08:00
parent 6c396454da
commit 4944fc8ebd
+7 -9
View File
@@ -13,8 +13,6 @@ use Database\Connection;
use Database\Db; use Database\Db;
use Exception; use Exception;
use Kiri\Cache\Redis; use Kiri\Cache\Redis;
use Kiri\Exception\ComponentException;
use Kiri\Exception\ConfigException;
use Kiri\Kiri; use Kiri\Kiri;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
@@ -123,8 +121,8 @@ class Gii
$redis->del('column:' . $this->tableName); $redis->del('column:' . $this->tableName);
} }
return match ($make) { return match ($make) {
'controller' => $this->getTable($db,1, 0), 'controller' => $this->getTable($db, 1, 0),
'model' => $this->getTable($db,0, 1), 'model' => $this->getTable($db, 0, 1),
default => [], default => [],
}; };
} }
@@ -139,7 +137,7 @@ class Gii
*/ */
private function getTable($db, $controller, $model): array private function getTable($db, $controller, $model): array
{ {
$tables = $this->getFields($this->getTables($db)); $tables = $this->getFields($this->getTables($db), $db);
if (empty($tables)) { if (empty($tables)) {
return []; return [];
} }
@@ -216,10 +214,10 @@ class Gii
* @return array * @return array
* @throws Exception * @throws Exception
*/ */
private function showAll($db): array private function showAll(Connection $db): array
{ {
$res = []; $res = [];
$_tables = Db::findAllBySql('show tables', [], $db); $_tables = Db::findAllBySql('show tables from `' . $db->database . '`', [], $db);
if (empty($_tables)) { if (empty($_tables)) {
return $res; return $res;
} }
@@ -247,7 +245,7 @@ class Gii
* @return array * @return array
* @throws * @throws
*/ */
private function getFields($tables): array private function getFields($tables, $db): array
{ {
$res = []; $res = [];
if (!is_array($tables)) { if (!is_array($tables)) {
@@ -255,7 +253,7 @@ class Gii
} }
foreach ($tables as $key => $val) { foreach ($tables as $key => $val) {
if (empty($val)) continue; if (empty($val)) continue;
$_tmp = Db::findAllBySql('SHOW FULL FIELDS FROM ' . $val, [], $this->db); $_tmp = Db::findAllBySql('SHOW FULL FIELDS FROM `' . $db->database . '`' . $val, [], $db);
if (empty($_tmp)) { if (empty($_tmp)) {
continue; continue;
} }