做了一些Google搜索後,我發現我們可以用PHP編輯我們的application.ini
。
下面是代碼:
$config = parse_ini_file(
APPLICATION_PATH . "/configs/application.ini",
TRUE,
INI_SCANNER_RAW
);
$config["production"]["$store.resources.layout.layout"] = "layout";
$layoutPath = 'APPLICATION_PATH "/modules/' . $store . '/layouts/scripts/"';
$config["production"]["$store.resources.layout.layoutPath"] = $layoutPath;
$result = Helper_common::write_ini_file(
$config,
APPLICATION_PATH . "/configs/application.ini",
TRUE
);
這裏parse_ini_file
用於檢索從application.ini
文件與常量內容。
write_ini_file
是我打電話重寫application.ini
文件的功能。
這裏是write_ini_file
功能:
public static function write_ini_file($assoc_arr, $path, $has_sections=FALSE) {
$content = "";
if ($has_sections) {
foreach ($assoc_arr as $key=>$elem) {
$content .= "[".$key."]\n";
foreach ($elem as $key2=>$elem2) {
if(is_array($elem2))
{
for($i=0;$i<count($elem2);$i++)
{
$content .= $key2."[] = ".$elem2[$i]."\n";
}
}
else if($elem2=="") $content .= $key2." = \n";
else $content .= $key2." = ".$elem2."\n";
}
}
}
else {
foreach ($assoc_arr as $key=>$elem) {
if(is_array($elem))
{
for($i=0;$i<count($elem);$i++)
{
$content .= $key2."[] = ".$elem[$i]."\n";
}
}
else if($elem=="") $content .= $key2." = \n";
else $content .= $key2." = ".$elem."\n";
}
}
if (!$handle = fopen($path, 'w')) {
return false;
}
if (!fwrite($handle, $content)) {
return false;
}
fclose($handle);
return true;
}