public function editAction() { $id = (int) $this->params()->fromRoute('idl', 0); if (!$id) { return $this->redirect()->toRoute('livre', array('action' => 'index')); } try { $message = $this->getLivreTable()->getLivre($id); } catch (\Exception $ex) { return $this->redirect()->toRoute('livre', array('action' => 'index')); } $perso = $this->getServiceLocator()->get('AuthService')->getIdentity(); if ($perso['id'] != $message->id_livre && $perso['id'] != $message->id_utilisateur) { return $this->redirect()->toRoute('livre', array('action' => 'index')); } $form = new LivreForm(); $form->bind($message); $form->get('submit')->setAttribute('value', 'Éditer votre message'); $request = $this->getRequest(); if ($request->isPost()) { $form->setInputFilter($message->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $this->getLivreTable()->saveLivre($message); // Rediriger vers sa liste de messages return $this->redirect()->toRoute('livre', array('action' => 'index')); } } return array('id' => $id, 'form' => $form); }
public function editAction() { $id = (int) $this->params()->fromRoute('id', 0); if (!$id) { return $this->redirect()->toRoute('livre', array('action' => 'add')); } // Get the Livre with the specified id. An exception is thrown // if it cannot be found, in which case go to the index page. try { $livre = $this->getLivreTable()->getLivre($id); } catch (\Exception $ex) { return $this->redirect()->toRoute('livre', array('action' => 'index')); } $form = new LivreForm(); $form->bind($livre); $form->get('submit')->setAttribute('value', 'Edit'); $request = $this->getRequest(); if ($request->isPost()) { $form->setInputFilter($livre->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $this->getLivreTable()->saveLivre($livre); // Redirect to list of livres return $this->redirect()->toRoute('livre'); } } return array('id' => $id, 'form' => $form); }