smarty = new Smarty(); // 确保路径以斜杠结尾 $viewPath = rtrim($this->config->get('view.config.view_path'), '/') . '/'; $compileDir = rtrim($this->config->get('view.config.compile_dir'), '/') . '/'; $this->smarty->setTemplateDir($viewPath); $this->smarty->setCompileDir($compileDir); // 调试输出路径(生产环境移除) error_log("Smarty模板路径: " . $viewPath); } public function render(string $template, array $data, array $config): string { foreach ($data as $key => $value) { $this->smarty->assign($key, $value); } return $this->smarty->fetch($template); } }