我们有一个带有 Smarty 模板引擎的 PHP 脚本插件,
它可以在带有 {plugin_name} 的模板文件中使用,但这需要确保它在每个模板文件中,问题是:
is there a way to auto-load this plugin whenever the scripts loads?
脚本不是开源的,但是Smarty和它的文件(比如Smarty.class.php等)没有加密。
编辑
我需要做的就是在加载模板文件之前自动加载一个 Smarty 插件(它与数据库的交互很少),这是否可能/只能通过 Smarty 文件实现? (脚本本身是加密的,但Smarty_Compiler.class.php、Smarty.class.php、Config_File.class.php等smarty核心函数是开源的)
最佳答案
这取决于您使用的 Smarty 版本。
使用 Smarty 3,您可以:
$smarty = new Smarty();
$smarty->setTemplatesDir(....);
$smarty->addPluginsDir('/path/to/your/plugins');
... stuff.
$smarty->display('template.tpl');
另请参阅:https://www.smarty.net/docs/en/api.add.plugins.dir.tpl
对于 Smarty2,我认为您需要做更多类似的事情 -
https://www.smarty.net/docsv2/en/api.register.function.tpl
或者,您将函数放入 libs/plugins 目录中,并使用正确的文件名和函数名...
关于php - 如何自动加载 smarty 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39137267/