/** * Méthode de modification d'une entrée * Récupère les données via le model et les injecte dans le formulaire * @return boolean */ public function edit() { if (!$this->actions->isEnabled('edit')) { Go::to404(); } $this->setTitle($this->titles->get('edit')); try { $form = new Form($this->formName); } catch (Exception $e) { $form = new Form($this->formName, false); $inputs = $this->model->generateInputsFromDescribe(); foreach ($inputs as $nam => $inp) { $form->setInput($nam, $inp); } } $data = $this->model->getTupleById($_GET["id"]); if (!$data) { Go::to($this->className); } $form->injectValues($data); if ($form->isValid()) { if ($this->model->updateById($_GET["id"], $form->getValues())) { $this->addContent("confirmation", Dictionary::term("backoffice.forms.editDone")); $this->dispatchEvent(new Event(self::EVENT_SUCCESSFUL_EDIT)); } else { $this->addContent("error", Dictionary::term("backoffice.forms.errorSQL")); $this->dispatchEvent(new Event(self::EVENT_FAILED_EDIT)); } $id = $_GET["id"]; $form->setUploadFileName($id); } else { $this->addContent("error", $form->getError()); } $this->setTemplate("default", "form"); $this->addContent("id", $this->model->id); $this->addForm("instance", $form); $this->addContent("h1", $this->h1->get('edit')); }