2013-05-02 170 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不可寫,您需要顯示實際路徑或顯示您用來嘗試使其可寫的命令。

相關問題