Exemplo n.º 1
0
 public function editAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('album', array('action' => 'add'));
     }
     try {
         $album = $this->getEntityManager()->find('Album\\Entity\\Album', $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->setData($request->getPost());
         if ($form->isValid()) {
             $form->bindValues();
             $this->getEntityManager()->flush();
             return $this->redirect()->toRoute('album');
         }
     }
     return array('id' => $id, 'form' => $form);
 }
Exemplo n.º 2
0
 public function editAction()
 {
     $id = (int) $this->getEvent()->getRouteMatch()->getParam('id');
     if (!$id) {
         return $this->redirect()->toRoute('album', array('action' => 'add'));
     }
     $album = $this->getAlbumTable()->getAlbum($id);
     $form = new AlbumForm();
     $form->setBindOnValidate(false);
     $form->bind($album);
     $form->get('submit')->setAttribute('value', 'Edit');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->post());
         if ($form->isValid()) {
             $form->bindValues();
             $this->getAlbumTable()->saveAlbum($album);
             // Redirect to list of albums
             return $this->redirect()->toRoute('album');
         }
     }
     return array('id' => $id, 'form' => $form);
 }