2011-08-04 36 views
2

這裏是我的目錄結構:爲什麼不能Smarty的加載此塊標記插件

./smartytest.php
./smarty31/*(庫等)
./plugins/block.sayhi .PHP

初始化Smarty的PHP代碼是:

require_once('smarty31/libs/Smarty.class.php'); 
$smarty = new Smarty(); 
$smarty->template_dir = getcwd() . '/templates'; 
$smarty->compile_dir = getcwd() . '/templates_c'; 
$smarty->plugins_dir[] = getcwd() . '/plugins'; 

該插件的PHP代碼:

<?php 
    function smarty_block_sayhi($params, $content, $smarty, $open) { 
     if (!$open) { 
      return 'Hello: ' . $content; 
     } 
    } 
?> 

該錯誤消息我得到的是這樣的:

Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "/mypath/phptests/templates/page.tpl" on line 11 "{sayhi}" unknown tag "sayhi"'

當插件是smarty31 /庫/ plugins目錄下,它加載的罰款。這個示例代碼是否不正確地初始化Smarty?

+0

「/mypath/phptests/templates/page.tpl」的內容是什麼?看起來你有一個無法識別的標籤 – Alex

+1

哇Smarty。這是過去的一次爆炸。人們仍然使用它? – Layke

回答

1
$smarty->plugins_dir[] = getcwd() . '/plugins'; 

應該是:

$existing = $smarty->getPluginsDir(); 
$existing[] = getcwd() . '/plugins'; 
$smarty->setPluginsDir($existing); 

原來我看到的是一個PHP 4例; Smarty 3.1使用PHP 5訪問修飾符,所以我無法以這種方式更改plugins_dir。

相關問題