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->getServiceLocator()->get('Album\\Model\\AlbumTable')->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()) { $this->getServiceLocator()->get('Album\\Model\\AlbumTable')->saveAlbum($album); // Redirect to list of albums return $this->redirect()->toRoute('album'); } } return array('id' => $id, 'form' => $form); }
public function editAction() { $auth = new AuthenticationService(); if (!$auth->hasIdentity()) { return $this->redirect()->toRoute('home'); } $id = (int) $this->params('id'); if (!$id) { return $this->redirect()->toRoute('addalbum'); } $album = $this->getAdminTable()->getAlbum($id); $form = new AlbumForm(); $form->bind($album); $form->get('submit')->setAttribute('value', 'edit'); $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); if ($form->isValid()) { $this->getAdminTable()->saveAlbum($album); return $this->redirect()->toRoute('album'); } } $viewModel = new ViewModel(array('form' => $form, 'id' => $id)); $viewModel->setTerminal(true); return $viewModel; }
public function editAction() { $auth = new AuthenticationService(); if (!$auth->hasIdentity()) { return $this->redirect()->toRoute('home'); } $id = (int) $this->params('id'); if (!$id) { return $this->redirect()->toRoute('addalbum'); } $album = $this->getAdminTable()->getAlbum($id); $form = new AlbumForm(); $form->bind($album); $form->get('submit')->setAttribute('value', 'edit'); $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); if ($form->isValid()) { $this->getAdminTable()->saveAlbum($album); return $this->redirect()->toRoute('album'); } } $sms = $this->getServiceLocator(); $categoryTable = $sms->get('Application\\Model\\CategoryTable'); $categorys = $categoryTable->fetchAllCategory(); $cat = array(0 => '--Select Category--'); foreach ($categorys as $category) { $cat[(int) $category->id] = $category->name; } $viewModel = new ViewModel(array('form' => $form, 'id' => $id, 'categorys' => $cat)); $viewModel->setTerminal(true); return $viewModel; }