public function saveAction()
 {
     //  Is not $_POST
     if (!$this->request->isPost()) {
         $this->view->disable();
         return $this->response->redirect($this->router->getControllerName());
     }
     $id = $this->request->getPost('id', 'int', null);
     if (!empty($id)) {
         $object = Configuration::findFirstById($id);
     } else {
         $object = new Configuration();
     }
     $form = new ConfigurationForm($object);
     $form->bind($_POST, $object);
     //  Form isn't valid
     if (!$form->isValid($this->request->getPost())) {
         foreach ($form->getMessages() as $message) {
             $this->flashSession->error($message->getMessage());
         }
         // Redirect to edit form if we have an ID in page, otherwise redirect to add a new item page
         return $this->response->redirect($this->router->getControllerName() . (!is_null($id) ? '/edit/' . $id : '/new'));
     } else {
         if (!$object->save()) {
             foreach ($object->getMessages() as $message) {
                 $this->flashSession->error($message->getMessage());
             }
             return $this->dispatcher->forward(['controller' => $this->router->getControllerName(), 'action' => 'new']);
         } else {
             $this->flashSession->success(t('Data was successfully saved'));
             return $this->response->redirect($this->router->getControllerName());
         }
     }
 }
示例#2
0
 /**
  * Load all configuration data
  */
 private static function loadConfiguration()
 {
     $configurations = Configuration::find();
     if (!count($configurations)) {
         return false;
     }
     foreach ($configurations as $configuration) {
         $value = $configuration->getValue();
         if ($configuration->getType() == self::TYPE_ARRAY) {
             $value = explode(self::ARRAY_TYPE_SEPARATOR, $configuration->getValue());
             $value = array_combine($value, $value);
         }
         self::$conf[$configuration->getKey()] = $value;
     }
     $cacheKey = 'configuration';
     $di = \Phalcon\DI::getDefault();
     $cacheService = $di->get('modelsCache');
     $cacheService->save($cacheKey, self::$conf);
     return true;
 }