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.
我經歷了整個確保文件夾實際上是可寫的,但是我仍然得到錯誤。有任何想法嗎?
做一些調試,以檢查是否需要你的模板目錄到你想要的東西.. do $ smarty-> getTemplateDir();並查看索引文件位於smarty對象指向的目錄中。 – Dinesh 2013-05-02 01:36:16
這取決於用戶服務器環境,但請確保您的apache用戶名是這些目錄的所有者。只是讓他們'777'可能並不總是工作。 – 2013-05-02 18:24:42