Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么可以';t Smarty加载此块标记插件_Php_Smarty - Fatal编程技术网

Php 为什么可以';t Smarty加载此块标记插件

Php 为什么可以';t Smarty加载此块标记插件,php,smarty,Php,Smarty,以下是我的目录结构: ./smartytest.php ./smarty31/*(libs等) ./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(

以下是我的目录结构:

./smartytest.php
./smarty31/*(libs等)
./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;
        }
    }
?>

我收到的错误消息如下:

致命错误:未捕获的异常“SmartyCompilerException”与消息 上的“模板中的语法错误”/mypath/phptests/templates/page.tpl 第11行“{sayhi}”未知标记“sayhi”

当插件位于smarty31/libs/plugins目录下时,它加载良好。此示例代码是否未正确初始化Smarty

$smarty->plugins_dir[] = getcwd() . '/plugins';
应该是:

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

原来我在看一个PHP4示例;Smarty 3.1使用PHP5访问修饰符,因此我无法以这种方式更改插件目录。

在“/mypath/phptests/templates/page.tpl”的内容中有什么?看起来你在thereWow Smarty中有一个无法识别的标签。那是过去的爆炸。人们还在用它吗?