2011-08-04 5 views
2

がここに私のディレクトリ構造である。このブロックタグのプラグインを読み込むことができませんはなぜSmartyのは

.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; 
     } 
    } 
?> 

私が取得エラーメッセージはこれです:プラグインがsmarty31/libsに/ pluginsディレクトリの下にあったとき

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

は、それが正常にロードされました。このサンプルコードはSmartyを正しく初期化していませんか?

+0

「/mypath/phptests/templates/page.tpl」の内容は何ですか?あなたがそこに認識されないタグを持っているように見える – Alex

+1

ワウスマイティ。それは過去からの爆発です。人々はまだそれを使用していますか? – 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をそのように変更することはできませんでした。