/**
  * @before _secured, _admin
  */
 public function settings()
 {
     $view = $this->getActionView();
     $config = Config::all();
     $view->set('config', $config);
     if (RequestMethods::post('submitEditSet')) {
         if ($this->checkCSRFToken() !== true) {
             self::redirect('/admin/');
         }
         $errors = array();
         foreach ($config as $conf) {
             $oldVal = $conf->getValue();
             $conf->value = RequestMethods::post($conf->getXkey(), '');
             if ($conf->validate()) {
                 Event::fire('admin.log', array('success', $conf->getXkey() . ': ' . $oldVal . ' - ' . $conf->getValue()));
                 $conf->save();
             } else {
                 Event::fire('admin.log', array('fail', $conf->getXkey() . ': ' . $conf->getValue()));
                 $errors[$conf->xkey] = array_shift($conf->getErrors());
             }
         }
         if (empty($errors)) {
             $view->successMessage(self::SUCCESS_MESSAGE_2);
             self::redirect('/admin/system/');
         } else {
             $view->set('errors', $errors);
         }
     }
 }
Esempio n. 2
0
 /**
  * Method save additional configuration into database
  * Config table is required
  * 
  * @param string $key
  * @param mixed $value
  * @return boolean
  */
 public function saveConfigToDb($key, $value)
 {
     if (Registry::get('database') instanceof \THCFrame\Database\Connector) {
         $conf = Config::first(array('xkey = ?' => $key));
         $conf->value = $value;
         if ($conf->validate()) {
             $conf->save();
             return true;
         } else {
             return false;
         }
     } else {
         throw new Exception\Argument('Connection to the database has not been initialized');
     }
 }
Esempio n. 3
0
 /**
  * Extends configuration loaded from config file for configuration loaded
  * form database
  */
 public function extendForDbConfig()
 {
     $ca = Config::all();
     if ($ca !== null) {
         foreach ($ca as $key => $value) {
             $this->_configArrMerged[$value->xkey] = $value->value;
         }
         $this->_parsed = ArrayMethods::toObject($this->_configArrMerged);
         Registry::set('configuration', $this->_parsed);
     }
 }