After doing some googling, I have found that we can edit our application.ini
with PHP.
Here is the code:
$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
);
Here parse_ini_file
is used to retrieve content from the application.ini
file with constants.
write_ini_file
is the function that I am calling to rewrite the application.ini
file.
Here is the write_ini_file
function:
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;
}