我为系统上的每个客户机都准备了一个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:"";
}
}
?>
你读过Zend_Config_Writer的文档吗?假设你已经加载了整个配置文件(而不仅仅是一个部分),你应该能够做到这一点(从文档中拉出来):
$writer = new Zend_Config_Writer_Ini(array('config' => $config,
'filename' => 'config.ini'));
$writer->write();