/** * create config object * DO NOT OVERRIDE * use startup() for your code * @param array $data * @param bool $json */ public final function __construct($data = array(), $json = false) { // set start data if ($json) { $this->config = json_array_decode($data); } else { $this->config = $data; } // call startup method $this->startup(); }
/** * set config * @param $name * @param $new_data * @throws \Exception */ public function saveConfig($name, $new_data) { try { //get original data from db $original_data = $this->app->db->getField('config', 'config_data', array('W' => "`config_name` = '" . $name . "'")); if (!empty($original_data)) { $original_data = json_array_decode($original_data); } else { $original_data = array(); } // update data foreach ($new_data as $key => $value) { $original_data[$key] = $value; } // convert back to json $new_data = array('config_name' => $name, 'config_data' => json_array_encode($original_data)); // save to db $this->app->db->save('config', $new_data, 'config_name', false); // Reload Data $this->reloadConfig($name, $new_data['config_data'], true); } catch (Exception $e) { throw $e; } }