2

所以我有一个使用旧版本 smarty 的旧网站,因为今天我想升级到最新版本,它给我一个错误:

[Fri Aug 19 11:21:19 2011] [error] [client ***.***.***.***] PHP Notice:  Undefined property: Smarty::$allow_php_tag in /work/smarty3.1rc1/Smarty.class.php on line 592
[Fri Aug 19 11:21:19 2011] [error] [client ***.***.***.***] PHP Fatal error:  Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "/work/templates/modules/main_module.tpl"  on line 2 "{php}" unknown tag "php"' in /work/smarty3.1rc1/sysplugins/smarty_internal_templatecompilerbase.php:596
Stack trace:
    #0 /work/smarty3.1rc1/sysplugins/smarty_internal_templatecompilerbase.php(382): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown tag "ph...', 2)
    #1 /work/smarty3.1rc1/sysplugins/smarty_internal_templateparser.php(2383): Smarty_Internal_TemplateCompilerBase->compileTag('php', Array)
    #2 /work/smarty3.1rc1/sysplugins/smarty_internal_templateparser.php(2865): Smarty_Internal_Templateparser->yy_r38()
    #3 /work/smarty3.1rc1/sysplugins/smarty_internal_templateparser.php(2965): Smarty_Internal_Templateparser->yy_reduce(38)
    #4 in /work/smarty3.1rc1/sysplugins/smarty_internal_templatecompilerbase.php on line 596

即使我把 Smarty 3.0.8 我得到同样的错误......因为如果网站充满{php}标签,删除不是一个选项。我能做些什么?

好的,按照@Pekka 的说明,我发现了 Smarty Security Next 问题:

$my_security_policy = new Smarty_Security($smarty);
$my_security_policy->allow_php_tag = true;
$my_security_policy->php_functions = array();
$my_security_policy->php_handling = Smarty::PHP_PASSTHRU;
$my_security_policy->php_modifier = array();
$my_security_policy->modifiers = array();

$smarty->enableSecurity($my_security_policy);

喊道:

[Fri Aug 19 12:06:40 2011] [error] [client ***.***.***.***] PHP Fatal error:  Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template .....' modifier 'strtolower' not allowed by security setting'

现在出了什么问题...$my_security_policy->php_functions = array();允许所有php函数..

4

1 回答 1

2

根据文档allow_php_tag现在是Smarty_Security类的属性,而不是Smarty. 有关如何使用它的示例,请参见页面。

我不知道这是什么时候改变的,但它很可能是一个新的 V3 功能。一个不错的!

于 2011-08-19T08:38:26.047 回答