Example #1
0
 /**
  * return config as json
  * @return mixed
  */
 public function getConfigJson()
 {
     return json_array_encode($this->config);
 }
Example #2
0
 /**
  * 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;
     }
 }