save() public method

save the object to the filename (active record style)
public save ( ) : boolean
return boolean
Beispiel #1
0
function write_ini()
{
    unlink(CONFIG);
    $config = new Config_Lite(CONFIG);
    foreach ($_POST as $parameter => $value) {
        $splitParameter = explode('-', $parameter);
        if ($value == "on") {
            $value = "true";
        }
        $config->set($splitParameter[0], $splitParameter[1], $value);
    }
    // save object to file
    try {
        $config->save();
    } catch (Config_Lite_Exception $e) {
        echo "\n" . 'Exception Message: ' . $e->getMessage();
    }
    $cache_new = "; <?php die(\"Access denied\"); ?>";
    // Adds this to the top of the config so that PHP kills the execution if someone tries to request the config-file remotely.
    $file = CONFIG;
    // the file to which $cache_new gets prepended
    $handle = fopen($file, "r+");
    $len = strlen($cache_new);
    $final_len = filesize($file) + $len;
    $cache_old = fread($handle, $len);
    rewind($handle);
    $i = 1;
    while (ftell($handle) < $final_len) {
        fwrite($handle, $cache_new);
        $cache_new = $cache_old;
        $cache_old = fread($handle, $len);
        fseek($handle, $i * $len);
        $i++;
    }
}
Beispiel #2
0
function write_ini()
{
    if (isset($_POST['reorder'])) {
        unlink('config.ini.php');
    }
    $config = new Config_Lite('config.ini.php');
    foreach ($_POST as $parameter => $value) {
        if ($parameter == "reorder") {
            continue;
        }
        $splitParameter = explode('-', $parameter);
        if ($splitParameter[0] != "removed") {
            if ($value == "on") {
                $value = "true";
            }
            $config->set($splitParameter[0], $splitParameter[1], $value);
        } else {
            try {
                $config->removeSection($splitParameter[1]);
            } catch (Config_Lite_Exception_UnexpectedValue $e) {
                //Ima catch it and move on because the section that was supposed to be removed is gone by this point.
            }
        }
    }
    // save object to file
    try {
        $config->save();
    } catch (Config_Lite_Exception $e) {
        echo "\n", 'Exception Message: ', $e->getMessage();
    } finally {
        echo true;
    }
}
Beispiel #3
0
<?php

require_once 'Config/Lite.php';
$config = new Config_Lite();
// read config file
$config->read('phpmussel.ini');
// get value from config file
var_dump($config->getBool('general', 'cleanup'));
var_dump($config->getBool('general', 'disable_cli'));
// set value in config file to false
$config->set('general', 'cleanup', false);
$config->set('general', 'disable_cli', true);
// get current value (not yet saved to the config file)
var_dump($config->getBool('general', 'cleanup'));
var_dump($config->getBool('general', 'disable_cli'));
// save new value to config file
$config->save();
// read updated config file
$config->read('phpmussel.ini');
// get saved value from config file
var_dump($config->read('phpmussel.ini')->getBool('general', 'cleanup'));
var_dump($config->read('phpmussel.ini')->getBool('general', 'disable_cli'));