0

我无法让 Smarty 模板引擎在我的本地测试服务器上正常工作。我的设置是这样的:

<?php
// put full path to Smarty.class.php
require('smarty/Smarty.class.php');
$smarty = new Smarty();
$smarty->testInstall();
$smarty->setTemplateDir('smarty/templates');
$smarty->setCompileDir('smarty/templates_c');
$smarty->setCacheDir('smarty/cache');
$smarty->setConfigDir('smarty/configs');

$smarty->assign('name', 'Ned');
$smarty->display('index.tpl');

?>

但是,我不断收到此错误:

Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file 'index.tpl'' in /var/www/WEBSITE/smarty/sysplugins/smarty_internal_templatebase.php:127 Stack trace: #0 /var/www/WEBSITE/smarty/sysplugins/smarty_internal_templatebase.php(374): Smarty_Internal_TemplateBase->fetch('index.tpl', NULL, NULL, NULL, true) #1 /var/www/WEBSITE/test.php(13): Smarty_Internal_TemplateBase->display('index.tpl') #2 {main} thrown in /var/www/WEBSITE/smarty/sysplugins/smarty_internal_templatebase.php on line 127

我使用了 testInstall 函数,它被返回:

Smarty Installation test...
Testing template directory...
/var/www/SteamKing/templates is OK.
Testing compile directory...
FAILED: /var/www/SteamKing/templates_c is not writable.
Testing plugins directory...
/var/www/SteamKing/smarty/plugins is OK.
Testing cache directory...
FAILED: /var/www/SteamKing/cache is not writable.
Testing configs directory...
FAILED: ./configs/ does not exist.
Testing sysplugin files...
... OK
Testing plugin files...
... OK
Tests complete.

我经历了整个过程,确保文件夹实际上是可写的,但我仍然得到错误。有任何想法吗?

4

1 回答 1

0

一方面,您分配路径的模板路径是错误的。路径/var/www/SteamKing不是smarty/

使用绝对路径通常是个好主意,这样您就可以移动文件而不必担心模板的去向。

至于为什么您的缓存和 template_c 不可写,您需要显示实际路径或显示您用来尝试使它们可写的命令。

于 2013-05-02T01:34:08.813 回答