function editAction() { $this->view->title = "Edit Album"; $form = new AlbumForm(array('legend' => $this->view->title)); $form->submit->setLabel('Update'); $this->view->form = $form; if ($this->_request->isPost()) { $form_data = $this->_request->getPost(); if ($form->isValid($form_data)) { $albums = new Albums(); $id = (int) $form->getValue('id'); $row = $albums->fetchRow('id=' . $id); $row->title = $form->getValue('title'); $row->description = $form->getValue('description'); $row->save(); $this->_redirect('/album/view/id/' . $id); } else { $form->populate($form_data); } } else { $id = (int) $this->_request->getParam('id', 0); if ($id > 0) { $albums = new Albums(); $album = $albums->fetchRow('id=' . $id); $form->populate($album->toArray()); } } $this->_helper->viewRenderer('form'); }
public function editAction() { $id = (int) $this->params()->fromRoute('id', 0); if (!$id) { return $this->redirect()->toRoute('Livre', array('action' => 'add')); } // Get the Album with the specified id. An exception is thrown // if it cannot be found, in which case go to the index page. try { $Livre = $this->getAlbumTable()->getAlbum($id); } catch (\Exception $ex) { return $this->redirect()->toRoute('Livre', array('action' => 'index')); } if (!$Livre) { return $this->redirect()->toRoute('Livre', array('action' => 'add')); } // var_dump($Livre); $form = new AlbumForm(); $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->getAlbumTable()->saveAlbum($Livre); // Redirect to list of Livres return $this->redirect()->toRoute('Livre'); } } return array('id' => $id, 'form' => $form); }