I often use an external file for saving settings, and found the built-in support for this very useful.
I add the following function to a lot of my projects, to take care of saving to files.
It works very much the same as the "editSetting" function, in that it serializes any arrays.
Upon loading the file, those values are automagically unserialized.
Code: Select all
// BOF - Zappo - PDF Print - Save Settings (to File)
public function saveSetting($filename, $data) {
$returner = "<?php\r\n".
"/*\r\n".
"* OpenCart Shopping Cart\r\n\r\n".
"***********************************************************\r\n".
"**** THIS FILE IS AUTOMATICALLY GENERATED!!! ****\r\n".
"**** USE ADMIN AREA TO CHANGE YOUR SETTINGS!!! ****\r\n".
"***********************************************************\r\n".
"*/\r\n\r\n";
foreach ($data as $key => $value) {
$returner .= " \$_['" . $key . "'] = ";
if (is_array($value)) {
$returner .= "unserialize('" . serialize($value) . "')";
} else {
$returner .= (is_numeric($value)) ? $value : "'" . $value . "'";
}
$returner .= ";\r\n";
}
$returner .= "?>";
if (substr($filename,-4) != '.php') $filename .= '.php';
if (@file_put_contents(DIR_CONFIG . $filename, $returner)) {
return true;
}
return false;
}
// EOF - Zappo - PDF Print - Save Settings (to File)