public function addAction() { $form = new LivreForm(); $form->get('submit')->setValue('Envoyer le message'); $perso = $this->getServiceLocator()->get('AuthService')->getIdentity(); $id = (int) $this->params()->fromRoute('idl', $perso['id']); if ($this->getLivreTable()->userExists($id)) { // Prise en compte de la requête $request = $this->getRequest(); if ($request->isPost()) { $message = new Livre(); $form->setInputFilter($message->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $message->exchangeArray($form->getData()); $message->date_message = new \Zend\Db\Sql\Expression("NOW()"); $message->id_livre = $id; $message->id_utilisateur = $perso['id']; $message->id_message = 0; $this->getLivreTable()->saveLivre($message); // Redirect to list of albums return $this->redirect()->toRoute('livre'); } } return array('form' => $form); } else { return "Aucun livre d'or n'est disponible à cette adresse."; } }
public function addAction() { $form = new LivreForm(); $form->get('submit')->setValue('Add'); $request = $this->getRequest(); if ($request->isPost()) { $livre = new Livre(); $form->setInputFilter($livre->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $livre->exchangeArray($form->getData()); $this->getLivreTable()->saveLivre($livre); // Redirect to list of livres return $this->redirect()->toRoute('livre'); } } return array('form' => $form); }