public function editAction() { $id = (int) $this->params()->fromRoute('id', 0); if (!$id) { return $this->redirect()->toRoute('album', 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 { $album = $this->getAlbumTable()->getAlbum($id); } catch (\Exception $ex) { return $this->redirect()->toRoute('album', array('action' => 'index')); } $form = new AlbumForm(); $form->bind($album); $form->get('submit')->setAttribute('value', 'Edit'); $request = $this->getRequest(); if ($request->isPost()) { $form->setInputFilter($album->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { // Perform album validation if ($form->isValidAlbum($album)) { // If the album passes validation then save it $this->getAlbumTable()->saveAlbum($album); } else { // Album did not pass validation! // Post message to user, album not allowed! // TODO: Add message to user did not pass validation. } // Redirect to list of albums return $this->redirect()->toRoute('album'); } } return array('id' => $id, 'form' => $form); }