Example #1
0
 public function create($data)
 {
     if ($this->authorizedRequest()) {
         $em = $this->getEntityManager();
         $album = new Album();
         $album->setArtist($data['artist']);
         $album->setTitle($data['title']);
         $em->persist($album);
         $em->flush();
         return new JsonModel(array('data' => $album->getId()));
     } else {
         return $this->defaultFailure();
     }
 }
Example #2
0
 public function addAction()
 {
     $form = new AlbumForm();
     $form->get('submit')->setValue('Add');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $album = new Album();
         $form->setInputFilter($album->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $album->populate($form->getData());
             $this->getEntityManager()->persist($album);
             $this->getEntityManager()->flush();
             return $this->redirect()->toRoute('album');
         }
     }
     return array('form' => $form);
 }
 public function addAction()
 {
     $form = new AlbumForm();
     $form->get('submit')->setAttribute('label', 'Add');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $album = new Album();
         $form->setInputFilter($album->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $album->exchangeArray($form->getData());
             $this->getEntityManager()->persist($album);
             $this->getEntityManager()->flush();
             // Redirect to list of albums
             return $this->redirect()->toRoute('dalbum');
         }
     }
     return array('form' => $form);
 }
 public function addAction()
 {
     $viewModel = $this->getViewModel();
     $form = new AlbumForm();
     $form->get('submit')->setAttribute('value', 'Add');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $album = new Album();
         $form->setInputFilter($album->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $album->exchangeArray($form->getData());
             $this->getAlbumTable()->saveAlbum($album);
             // Redirect to list of albums
             return $this->redirect()->toRoute('album-front-album');
         }
     }
     return $viewModel->setVariables(array('form' => $form));
 }