public function saveAction() { // Is not $_POST if (!$this->request->isPost()) { $this->view->disable(); return $this->currentRedirect(); } $id = $this->request->getPost('id', 'int', null); if (!empty($id)) { $object = Pages::findFirstById($id); } else { $object = new Pages(); } $form = new PagesForm($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->getPathController() . (!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->getPathController(), 'action' => 'new']); } else { $this->flashSession->success(t('Data was successfully saved')); return $this->response->redirect($this->getPathController()); } } }
public function aboutAction() { $this->tag->setTitle(t('About')); $this->view->object = Pages::findFirstByKey('about'); }