0

为了正确使用 Smarty,我创建了一个配置文件。文件结构是这样的:

/Smarty/
/Smarty/cache
/Smarty/configs
/Smarty/configs/main.conf
/Smarty/plugins
/Smarty/sysplugins
/Smarty/templates_c
/templates/
/templates/main.tpl
index.php

在 main.tpl 我尝试通过以下方式从 /Smarty/configs/main.conf 加载 main.conf: {config_load "main.conf"}如下所述:http ://www.smarty.net/docs/en/language.config.variables.tpl 这没有'不起作用(“致命错误:未捕获的异常'SmartyException'带有消息'无法读取配置文件'main.conf''在......”),但这确实有效:

{config_load "/var/www/vhosts/*domain*/subdomains/cms/httpdocs/Smarty/configs/main.conf"}

为什么第一个示例不起作用?我之前确实通过以下方式设置了配置目录:

$smarty->setConfigDir(SMARTY_DIR.'configs/');

但是找不到配置目录。有人可以帮我吗?提前致谢!

4

2 回答 2

1

我遇到了同样的问题,我在 CodeIgniter 中集成了 smarty。这就是我所做的
1)$this->smarty->addConfigDir('YourPath');
在你的情况下可能会变成$smarty->addConfigDir('YourPath');

var_dump($this->smarty->getConfigDir());然后在浏览器中打印。
在你的情况下可能会变成var_dump($smarty->getConfigDir());

2)在那之后,你可能会改变$this->smarty->setConfigDir('YourPath'); 你的情况,可能会变得$smarty->setConfigDir('YourPath');
适用于我的情况。

于 2013-02-23T14:16:23.963 回答
0

这是我使用的配置示例,它对我来说很好用

/////Smarty including
require_once('libs/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = 'template'; // template folder
$smarty->compile_dir = 'cache'; // Create a Folder Cache with 777 Permission

此设置适用于最新的 smarty 版本 Smarty 3.x。

于 2013-10-01T18:34:20.143 回答