为什么打印配置数组给空数组


Why printing config array gives empty Array?

$tpl = new Smarty();
$tpl->configLoad('compose.conf');
$config = $tpl->getConfigVars();
print_r($config);
返回

Array() 

是什么,我做错了吗?

compose.conf

[jquery]
jquery = lib/jquery/jquery.js
[jquery_validate]
css=res/css/jquery.validate.css
js=lib/jquery/jquery.validate.js
X=jquery

[bootstrap_css]
main = lib/bootstrap/css/bootstrap.min.css
theme = lib/ootstrap-theme.min.css
[bootstrap_js]
js = lib/bootstrap/js/bootstrap.min.js
X=jquery
[bootstrap]
X=bootstrap_css,bootstrap_js
[utils]
utils=lib/utils/utils.js
odo=lib/utils/utils.odo.js
require=libutils/utils.require.js
template=lib/utils/utils.template.js
X=jquery

在你的smarty plugins目录下smarty_internal_config.php搜索语句

if (!empty($sections)) {

现在用

替换该语句
    if($sections=='*'){
        foreach ($_config_vars['sections'] as $key=>$value) {
            if (isset($value['vars'])) {
                $scope_ptr->config_vars[$key] = $value['vars'];
            }
        }
    } else if (!empty($sections)) {

,在加载文件时像这样使用

$tpl = new Smarty();
$tpl->configLoad('compose.conf','*');
$config = $tpl->getConfigVars();
print_r($config);

这:)

根据parse_ini_file的手册:

注意:有保留字,不能用作ini文件的键。这些包括:null yesno true, false,>>> on & lt; & lt; & lt; off none。"null"、"off"、"no"、"false"的取值结果为""""。"on"、"yes"answers"true"的取值结果为""1""。字符?{}|&~![()^"不能在键的任何地方使用,并且在值中有特殊的含义。

如果我们尝试在你的文件上执行parse_ini_file(或parse_ini_string),我们会得到以下错误:

警告:语法错误,第7行Unknown中的意外BOOL_TRUE在/tmp/execpad-e67cf6f095ae/source-e67cf6f095ae第32行

因此,Smarty在尝试解析INI文件时出现错误(我假设它在内部使用这些函数之一),因为您使用保留字。解决方案是简单地将ON重命名为其他名称。

:

Smarty不使用这些函数,但是它的解析器复制了这些函数。smarty_internal_configfilelexer.php的第313行指向"on":
if (!$this->smarty->config_booleanize || !in_array(strtolower($this->value), Array("true", "false", "on", "off", "yes", "no")) ) {
//                                                                                                   ^^