CONFIG / Lite和Arrays

时间:2016-01-07 11:22:28

标签: php pear

刚开始使用Config / Lite(https://github.com/pear/Config_Lite

但似乎它不喜欢数组变量,例如我有以下我的INI文件:

    [Meta Tags]
    meta[site_description] = ""
    meta[site_keyword] = ""
    meta[site_title] = "FooBar"
    meta[site_type] = "Website"
    meta[site_url] = "site.com"
    meta[site_image] = "" 

如果我运行以下内容:

$lite = new Config_Lite("myfile", LOCK_EX);
$lite->set("MetaTags", "meta[site_keyword]", "keyword");
$lite->save();

我的INI文件中包含以下内容:

    [Meta Tags]
    meta[site_description] = ""
    meta[site_keyword] = ""
    meta[site_title] = "FooBar"
    meta[site_type] = "Website"
    meta[site_url] = "site.com"
    meta[site_image] = "" 
    meta[site_keyword] = "keyword"

似乎没有意识到已经有一个名为meta [site_keyword]的值,只是创建一个新条目。我做错了吗?

1 个答案:

答案 0 :(得分:2)

我不确定你是否做错了...... 这就是我使用Config_Lite更新一个特定行的方法:

<?php
require_once 'Config/Lite.php';
$lite = new Config_Lite("myfile", LOCK_EX);
$meta = ($lite->get('Meta Tags', 'meta'));
$meta['site_keyword'] = "keyword";
$lite->setSection("Meta Tags", ['meta' => $meta]);
$lite->save();