2014-05-18 49 views
0
$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 
+1

是什么'compose.conf'包含哪些内容? – mbanzon

+0

它包含配置变量,请参阅编辑。 – LNT

+0

错误日志中是否有任何内容?也许你的意思是调用'config_load'而不是'configLoad'? – mbanzon

回答

1

在你的Smarty插件目录 smarty_internal_config.php 搜索statment

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); 

完蛋了:)

1

parse_ini_file手动:

注:有保留其一定不能被用作用于INI文件键字。这些措施包括:nullyesnotruefalse,>>>on < < <,offnone。值null,off,nofalse导致""。值on,yestrue导致"1"。字符?{}|&~![()^"不得在密钥中的任何位置使用,并且在值中具有特殊含义。

如果我们试图在你的文件we get the following error执行parse_ini_file(或parse_ini_string):

警告:语法错误,在/ tmp/execpad-e67cf6f095ae在未知的意外BOOL_TRUE线路7 /线32上的源-e67cf6f095ae

因此,当尝试使用Smarty时,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"))) { 
//                         ^^ 
+1

用X试过了,还没有工作 – LNT

+0

@LNT'bootstrap_js'还剩下一个:'ON = jquery' – h2ooooooo

+1

对不起,在实际代码中删除了所有代码,没有成功。 – LNT