setName('makemodel') ->setDescription('the makemodel command'); } static $schema = 'bugonline'; static $prefix = 'Devcloud'; static $epp = 'bug'; protected function execute(Input $input, Output $output) { //获取表名 $tables = Db::query("SELECT TABLE_NAME as 'name' from information_schema.tables WHERE TABLE_SCHEMA = :dataBase and TABLE_TYPE='BASE TABLE'", ['dataBase' => self::$schema]); foreach ($tables as $key => $value) { foreach ($value as $item) { //获取字段名称和备注 $COLUMNS = Db::query('select COLUMN_NAME,DATA_TYPE,COLUMN_COMMENT from information_schema.COLUMNS where table_name = :item and table_schema = :dataBase', ['item' => $item, 'dataBase' => self::$schema]); $dir = app_path().self::$epp."/model/". self::snakeToCamel($item) . '.php'; if(file_exists($dir)) continue; $file = fopen($dir, 'w'); fwrite($file, '' ."'" . $COLUMN['DATA_TYPE'] . "'" . ',' . '//' . $COLUMN['COLUMN_COMMENT'] . PHP_EOL; fwrite($file, $content); } $content = ' ];'; fwrite($file, $content); fwrite($file, PHP_EOL . '}'); fclose($file); } } } private static function snakeToCamel($str, $capitalized = true) { $result = str_replace(['_',self::$prefix], ['',""], ucwords($str, '_')); echo $result."--"; echo ucwords($str, '_'); if (!$capitalized) { $result = lcfirst($result); } return $result; } }