我使用Config::save('key', $value);
public static function save($params, $value)
{
$parts = explode('.', $params);
$count = count($parts);
$mainFile = PANEL_PATH.'/conf.php';
$mainConfig = include $mainFile;
if($count == 1)
{
if(isset($mainConfig[$parts[0]]))
{
$mainConfig[$parts[0]] = $value;
}
}
elseif($count == 2)
{
if(isset($mainConfig[$parts[0]][$parts[1]]))
{
$mainConfig[$parts[0]][$parts[1]] = $value;
}
}
elseif($count == 3)
{
if(isset($mainConfig[$parts[0]][$parts[1]][$parts[2]]))
{
$mainConfig[$parts[0]][$parts[1]][$parts[2]] = $value;
}
}
elseif($count == 4)
{
if(isset($mainConfig[$parts[0]][$parts[1]][$parts[2]][$parts[3]]))
{
$mainConfig[$parts[0]][$parts[1]][$parts[2]][$parts[3]] = $value;
}
}
ob_start();
echo var_export($mainConfig);
$content = ob_get_contents();
ob_end_clean();
$content = str_replace(" ", "\t", $content);
$content = str_replace("\n\tarray (", "array(", $content);
$content = str_replace("\n\t\tarray (", "array(", $content);
$content = str_replace("\n\t\t\tarray (", "array(", $content);
$mainFileHandler = fopen($mainFile, 'w+');
$mainFileWrite = fwrite($mainFileHandler, "<?php\n\nreturn " . $content . ";");
if($mainFileWrite > 0)
{
return true;
}
else
{
return false;
}
fclose($mainFileHandler);
}
conf.php文件如下所示:
<?php
return array (
'name' => '<NAME>',
'license' => '<LICENSE>',
'url' => '<URL>',
'usage_id' => '<USAGE_ID>',
'installed' => '<INSTALLED>'
);
所以当我做这个陈述时
if (Config::save('usage_id', 'USAGE_ID') && Config::save('license', 'LICENSE'))
{
echo "Reset License";
}
它只重置license
变量,似乎它跳过了第一个变量。代码是否有问题导致它像这样?
如果需要更多代码,请告诉我,我很乐意提供。