1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- require 'vendor/autoload.php'; // 引入 Composer 的自动加载文件
- use inter\gen\DbStruct2ClassProcess;
- use inter\gen\ProcessConfig;
- use inter\mysqlStruct\Struct;
- use inter\storage\mysql\Config;
- use inter\storage\mysql\DB;
- use Smarty\Smarty;
- $database = 'new_energy';
- //$database = 'bms_alarm';
- //$database = 'business';
- $dbConfig = new Config('101.37.90.21', "", 'root', 'QAZwsx!@#456', $database);
- $db = new DB($dbConfig);
- $dbProcess = new Struct($db);
- $dbProcess->SelectDatabase($database);//->AddUseTable("dh_admin_commission_account");
- $dbStruct = $dbProcess->GetDatabase();
- $config = new ProcessConfig();
- $config->savePath = "gen";
- $config->isHasGetFunc = true;
- $config->isHasSetFunc = true;
- //$config->fileNamePrefix = "";
- //$config->SetNamespace('common/table/'.$database);
- //$config->addUse("common/table/TableModelBase");
- //$config->extends[] = "TableModelBase";
- $config->fileNameSuffix = "Query";
- $config->addUse("yii/db/ActiveQuery");
- $config->SetNamespace('common/table/'.$database.'/query');
- $config->extends[] = "ActiveQuery";
- $opt = new DbStruct2ClassProcess($config, $dbStruct);
- $files = $opt->GetFiles();
- $smarty = new Smarty(); // 创建 Smarty 对象实例
- foreach ($files as $file) {
- // 配置 Smarty
- $smarty->setTemplateDir('TPL') // 设置模板目录
- ->setCompileDir('gen/templates_c'); // 设置编译目录
- // 分配变量到模板
- $smarty->assign('file', $file);
- // 渲染模板
- //$content = $smarty->fetch('template.tpl');
- $content = $smarty->fetch('query.tpl');
- // 保存内容到文件
- $filePath = $file->GetPath() . '/' . $file->GetFileName();
- file_put_contents($filePath, $content);
- }
|