public function addAction() { $this->view->pick(['admin/edit']); $form = new PublicationForm(); $model = new Publication(); $type = $this->dispatcher->getParam('type'); if ($type) { $typeEntity = Type::getCachedBySlug($type); $form->get('type_id')->setDefault($typeEntity->getId()); $this->view->type = $type; } if ($this->request->isPost()) { $post = $this->request->getPost(); $form->bind($post, $model); if ($form->isValid()) { if ($model->create()) { $form->bind($post, $model); $model->updateFields($post); if ($model->update()) { $this->flash->success($this->helper->at('Publication created')); return $this->redirect($this->url->get() . 'publication/admin/edit/' . $model->getId() . '?lang=' . LANG); } else { $this->flashErrors($model); } } else { $this->flashErrors($model); } } else { $this->flashErrors($form); } } $this->view->model = $model; $this->view->form = $form; $this->helper->title($this->helper->at('Create a publication'), true); }