main.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. require 'vendor/autoload.php'; // 引入 Composer 的自动加载文件
  3. use inter\gen\DbStruct2ClassProcess;
  4. use inter\gen\ProcessConfig;
  5. use inter\mysqlStruct\Struct;
  6. use inter\storage\mysql\Config;
  7. use inter\storage\mysql\DB;
  8. use Smarty\Smarty;
  9. $database = 'new_energy';
  10. //$database = 'bms_alarm';
  11. //$database = 'business';
  12. $dbConfig = new Config('101.37.90.21', "", 'root', 'QAZwsx!@#456', $database);
  13. $db = new DB($dbConfig);
  14. $dbProcess = new Struct($db);
  15. $dbProcess->SelectDatabase($database);//->AddUseTable("dh_admin_commission_account");
  16. $dbStruct = $dbProcess->GetDatabase();
  17. $config = new ProcessConfig();
  18. $config->savePath = "gen";
  19. $config->isHasGetFunc = true;
  20. $config->isHasSetFunc = true;
  21. //$config->fileNamePrefix = "";
  22. //$config->SetNamespace('common/table/'.$database);
  23. //$config->addUse("common/table/TableModelBase");
  24. //$config->extends[] = "TableModelBase";
  25. $config->fileNameSuffix = "Query";
  26. $config->addUse("yii/db/ActiveQuery");
  27. $config->SetNamespace('common/table/'.$database.'/query');
  28. $config->extends[] = "ActiveQuery";
  29. $opt = new DbStruct2ClassProcess($config, $dbStruct);
  30. $files = $opt->GetFiles();
  31. $smarty = new Smarty(); // 创建 Smarty 对象实例
  32. foreach ($files as $file) {
  33. // 配置 Smarty
  34. $smarty->setTemplateDir('TPL') // 设置模板目录
  35. ->setCompileDir('gen/templates_c'); // 设置编译目录
  36. // 分配变量到模板
  37. $smarty->assign('file', $file);
  38. // 渲染模板
  39. //$content = $smarty->fetch('template.tpl');
  40. $content = $smarty->fetch('query.tpl');
  41. // 保存内容到文件
  42. $filePath = $file->GetPath() . '/' . $file->GetFileName();
  43. file_put_contents($filePath, $content);
  44. }