SelectDatabase($database); //->AddUseTable("dh_admin_commission_account"); $dbStruct = $dbProcess->GetDatabase(); $config = new ProcessConfig(); $config->savePath = "gen"; $config->isHasGetFunc = true; $config->isHasSetFunc = true; if ($type == "record") { // record $tpl = "record.tpl"; $config->fileNameSuffix = "Record"; $config->SetNamespace('common/table/' . $database . '/record'); $config->addUse("Yii"); $config->addUse("common/table/NewEnergyDBRecord"); $config->extends[] = "NewEnergyDBRecord"; } else if ($type == "query") { // query $tpl = "query.tpl"; $config->SetNamespace('common/table/' . $database . '/query'); $config->fileNameSuffix = "Query"; $config->addUse("common/table/BaseQuery"); $config->extends[] = "BaseQuery"; } else if ($type == "gset") { // get set $tpl = "setGet.tpl"; $config->fileNameSuffix = "Trait"; $config->SetNamespace('common/table/' . $database . '/getter_setter'); } else { echo "不支持的类型"; return; } $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); $smarty->assign("database", $database); // 渲染模板 //$content = $smarty->fetch('template.tpl'); $content = $smarty->fetch($tpl); // 保存内容到文件 $filePath = $file->GetPath() . '/' . $file->GetFileName(); file_put_contents($filePath, $content); }