如何从PHP后台读取smarty配置变量?
对于从Smarty的配置文件中读取变量值的Smarty类,我可以在PHP中使用什么函数 这是我的密码:如何从PHP后台读取smarty配置变量?,php,smarty,Php,Smarty,对于从Smarty的配置文件中读取变量值的Smarty类,我可以在PHP中使用什么函数 这是我的密码: <? session_start(); require('libs/Smarty.class.php'); $smarty = new Smarty; $smarty->config_load("settings.conf"); include('settings.php'); include('meta.php'); $smarty->debugging = f
<?
session_start();
require('libs/Smarty.class.php');
$smarty = new Smarty;
$smarty->config_load("settings.conf");
include('settings.php');
include('meta.php');
$smarty->debugging = false;
$smarty->caching =false;
$smarty->cache_lifetime = 120;
include("categories.php");
include("manufacturers.php");
include("logos.php");
print_r($smarty->getConfigVariable("showCategories"));
close_database_session($dbconn);
//$smarty->display('index.tpl');
?>
With(您必须事先加载配置)
文档中的示例:
// get loaded config template var #foo#
$myVar = $smarty->get_config_vars('foo');
// get all loaded config template vars
$all_config_vars = $smarty->get_config_vars();
更新(Smarty 3.0 RC1):
对于Smarty 3.0 RC1,它是
$smarty->configLoad($config_file, $sections = null)
// and
$smarty->getConfigVariable($variable)
注意:目前还没有官方文档,但可用的方法已在附带的自述文件中列出。With(您必须事先加载配置)
文档中的示例:
// get loaded config template var #foo#
$myVar = $smarty->get_config_vars('foo');
// get all loaded config template vars
$all_config_vars = $smarty->get_config_vars();
更新(Smarty 3.0 RC1):
对于Smarty 3.0 RC1,它是
$smarty->configLoad($config_file, $sections = null)
// and
$smarty->getConfigVariable($variable)
注意:目前还没有官方文档,但可用的方法在附带的自述文件中列出。以下是获取smarty分配的配置变量的简单方法:
打印您的$smarty
对象,并记下您的配置变量
获取这些变量,例如settings.conf
:
$category_title1 = $smarty->_config[0]['vars']['driving_license_category'];
然后,您可以在PHP中随意使用。以下是获取smarty分配的配置变量的简单方法:
打印您的$smarty
对象,并记下您的配置变量
获取这些变量,例如settings.conf
:
$category_title1 = $smarty->_config[0]['vars']['driving_license_category'];
然后,您可以在PHP中随心所欲地使用它。我使用以下代码:
$templ->fetch('template_that_loads_config.tpl');
print_r($templ->_config[0]['vars']);
我是用这个代码做的:
$templ->fetch('template_that_loads_config.tpl');
print_r($templ->_config[0]['vars']);
smarty->configLoad(…)
生成如下通知
“注意:函数调用'config_load'未知或已弃用。”
一种解决方法是在调用前加一个@,如
@smarty->configLoad($cfgFile)
smarty->configLoad(…)
生成如下通知
“注意:函数调用'config_load'未知或已弃用。”
一种解决方法是在调用前加一个@,如
@smarty->configLoad($cfgFile)
我现在从PHP得到的是:注意:函数调用'config\u load'未知或不推荐使用。在第57行的C:\xampp\htdocs\rondcom\libs\sysplugins\smarty\u internal\u wrapper.php中,我使用的是smarty 3。@欧文:更新了我的答案,这些方法列在自述文件中。它正在工作,但给出了错误消息。但如果我把@放在前面,一切都会好的。谢谢这里是我现在从PHP得到的:注意:函数调用'config_load'未知或不推荐使用。在第57行的C:\xampp\htdocs\rondcom\libs\sysplugins\smarty\u internal\u wrapper.php中,我使用的是smarty 3。@欧文:更新了我的答案,这些方法列在自述文件中。它正在工作,但给出了错误消息。但如果我把@放在前面,一切都会好的。非常感谢。