2013-05-02 146 views
0

我无法使Smarty模板引擎在我的本地测试服务器上正常工作。我有它设置如下: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. 

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

+0

做一些调试,以检查是否需要你的模板目录到你想要的东西.. do $ smarty-> getTemplateDir();并查看索引文件位于smarty对象指向的目录中。 – Dinesh 2013-05-02 01:36:16

+0

这取决于用户服务器环境,但请确保您的apache用户名是这些目录的所有者。只是让他们'777'可能并不总是工作。 – 2013-05-02 18:24:42

回答

0

对于一件事,模板路径在指定路径的地方是错误的。路径是/var/www/SteamKing不是smarty/

通常使用绝对路径是一个好主意,因此您可以移动文件而无需担心模板的位置。

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

相关问题