我尝试用smarty用file_get_contents读取外部数据
然而,我得到了这个错误。
Fatal error: Smarty error: [in /opt/lampp/htdocs/blog/serendipity/templates/templates3/index.tpl line 107]: [plugin] (secure mode) modifier 'file_get_contents' is not allowed (Smarty_Compiler.class.php, line 1934) in /opt/lampp/htdocs/blog/serendipity/bundled-libs/Smarty/libs/Smarty.class.php on line 1093
有没有其他方法可以获取数据?或者我如何让smarty使用这个函数?
发布于 2012-05-21 17:57:16
也许{fetch}插件可以在这里提供帮助。在任何情况下,@shadyyx都是正确的。你可能只想分配内容,让你的生活变得更简单。
发布于 2012-05-21 17:55:09
您应该做的是配置smarty安全设置。
源码如下:
if ($smarty->security && !in_array($_name, $smarty->security_settings['MODIFIER_FUNCS'])) {
$_message = "(secure mode) modifier '$_name' is not allowed";
} else {
if (!function_exists($_name)) {
$_message = "modifier '$_name' is not implemented";
} else {
$_plugin_func = $_name;
$_found = true;
}
}
发布于 2012-05-21 17:55:29
错误提示您处于安全模式。这意味着Smarty不允许您运行PHP脚本(取决于安全模式级别)或调用许多PHP函数。
你可以关闭我不推荐的安全模式,或者你应该把PHP代码放到你的控制器中,并在PHP控制器中分配var:
...
$data = file_get_contents('path_to_json');
$smarty->assign('data', $data);
...
或
$smarty->assign('data', file_get_contents('path_to_json'));
https://stackoverflow.com/questions/10682816
复制相似问题