如何自动加载smarty插件

Vla*_*mir 20 php smarty

我们有一个带有Smarty模板引擎的PHP脚本插件,

它可以在{plugin_name}的模板文件中使用,但需要确保它在每个模板文件上,问题是:

有没有办法在脚本加载时自动加载此插件?

脚本不是开源的,但Smarty及其文件(如Smarty.class.php等)未加密.

编辑

我需要做的就是在模板文件加载之前自动加载Smarty插件(与数据库的交互很少),这是否可以/只用Smarty文件实现?(脚本本身是加密的,但Smarty_Compiler.class.php,Smarty.class.php,Config_File.class.php和其他聪明的核心功能都是开源的)

Dav*_*win 2

这取决于您使用的 Smarty 版本。

使用 Smarty 3,您可以执行以下操作:

$smarty = new Smarty();
$smarty->setTemplatesDir(....);
$smarty->addPluginsDir('/path/to/your/plugins');
... stuff.
$smarty->display('template.tpl');
Run Code Online (Sandbox Code Playgroud)

另请参阅: https: //www.smarty.net/docs/en/api.add.plugins.dir.tpl

对于 Smarty2,我认为你需要做更多类似这样的事情 -

https://www.smarty.net/docsv2/en/api.register.function.tpl

或者,将函数放入 libs/plugins 目录中,并使用正确的文件名和函数名称...