我的系统上的每个客户端都有一个ini文件,并添加了一个新的部分和密钥以便即时创建。
我需要一些这样的想法:
当前的ini文件:
[section_a]
key_a=1
key_b-2
需要将此代码(使用php / zend)更改为:
[section_a]
key_a =1
key_b = 2
[section_b]
key_a = 1
需要添加一个名为section_b的新部分,其中包含一个名为key_a的新密钥,但我在Zend_Ini_Config上找不到任何类似“$ ini> add('section_b','key_a')”。
观测值:
Php "magic" like $ini->$new_prop->$new_prop = "1" , dont work to!
任何帮助!!
更新
<?php
class SystemConfigHelper
{
public static $data;
public static function load()
{
if(!defined("ACCOUNT_ID"))
return true;
try
{
$url = explode('.', $_SERVER['HTTP_HOST']);
self::$data = new Zend_Config_Ini(ACCOUNTS_PATH . "/" . ACCOUNT_ID . "/system-config.ini",null,array("allowModifications" => true));
return true;
}
catch(Exception $e)
{
die($e->getMessage());
return false;
}
}
public static function save()
{
try
{
$url = explode('.', $_SERVER['HTTP_HOST']);
$writer = new Zend_Config_Writer_Ini(array('config' => self::$data,
'filename' => ACCOUNTS_PATH . "/" . ACCOUNT_ID . "/system-config.ini"));
$writer->write();
}
catch(Exception $e)
{
die($e->getMessage());
return false;
}
}
public static function getParam($section,$key)
{
return self::$data->$section->$key;
}
public static function sync($data)
{
//self::$data = $data;
//return;
foreach(self::$data as $section => $param)
{
foreach($param as $key => $value)
{
self::$data->$section->$key = $data[$section][$key];
}
}
}
public static function getParamAs($section,$key,$as)
{
return self::$data->$section->$key==1?$as:"";
}
}
?>
答案 0 :(得分:0)
您是否阅读了Zend_Config_Writer上的文档?假设您已经加载了整个配置文件(而不仅仅是一个部分),您应该可以执行此操作(从文档中向右拉):
$writer = new Zend_Config_Writer_Ini(array('config' => $config,
'filename' => 'config.ini'));
$writer->write();