CrudModel.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\crud\command;
  3. use app\crud\make\AutoMake;
  4. use app\crud\make\make\ModelMake;
  5. use think\console\Command;
  6. use think\console\Input;
  7. use think\console\input\Option;
  8. use think\console\Output;
  9. class CrudModel extends Command
  10. {
  11. protected function configure()
  12. {
  13. $this->setName('auto crud')
  14. ->addOption('table', 't', Option::VALUE_OPTIONAL, 'the table name', null)
  15. ->addOption('controller', 'c', Option::VALUE_OPTIONAL, 'the controller name', null)
  16. ->addOption('name', 'm', Option::VALUE_OPTIONAL, 'the name', null)
  17. ->setDescription('auto make crud file');
  18. }
  19. protected function execute(Input $input, Output $output)
  20. {
  21. $table = $input->getOption('table');
  22. if (!$table) {
  23. $output->error("请输入 -t 表名");
  24. exit;
  25. }
  26. $controller = $input->getOption('controller');
  27. if (!$controller) {
  28. $output->error("请输入 -c 控制器名");
  29. exit;
  30. }
  31. $path = 'admin';
  32. $name = $input->getOption('name');
  33. if (!$name) {
  34. $name = '';
  35. }
  36. $make = new AutoMake();
  37. // 执行生成model策略
  38. $make->executeText(new ModelMake());
  39. $make->executeCreate($table, $path, '');
  40. $output->info($name . "model make success");
  41. }
  42. }